本文介绍了功能提前触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图尝试从函数回调一个值,但是,回调总是未定义的,因为 jQuery 日期选择器从来没有机会设置 var sdate,因此提醒我它是未定义的.我真的需要你的帮助,似乎无法解决这个问题.

I am trying to attempt to call back a value from a function, however, the call back is always undefined because the jQuery Date Picker never has a chance to set the var sdate, thus alerts me that it is undefined. I realy need your help and can't seem to get passed this problem.

var sdate
function test() {


    select_date()
    alert(sdate)

    }


  function select_date() {

    $('#dd').dialog({
        autoOpen: true,
        modal: true,
        overlay: {
            opacity: 0.5,
            background: 'black'
        },
        title: "title",
        height: 265,
        width: 235,
        draggable: false,
        resizable: false

    }); //end of dialog

    var x
    $('#d1').datepicker({
        onSelect: function() {
            sdate = $(this).val();
            $("#dd").dialog("close");
        }
    });
    return sdate

}

推荐答案

这对您有什么作用?

$('#d1').datepicker({
        onSelect: function() {
           sdate = $(this).val(); 
          //set value to the global variable (although not the best approach)
            $("#dd").dialog("close");
        }
 });

这篇关于功能提前触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 03:00