功能触发早 [英] Function triggering early

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

问题描述

我试图从函数中回调一个值,但是,回调总是未定义的,因为jQuery Date Picker永远没有机会设置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");
        }
 });

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆