如何在一些被调用函数中传递jquery对话框按钮函数的返回值

时间:2015-10-26 13:53:47

标签: javascript jquery jquery-ui-dialog

我想得到jquery对话框的返回值,取决于对话的返回值true或false我需要调用其他函数,这是我的试用版,但这里是返回[object object]。

 function someFunction()
    {
      returnVal=$('#uploadMsrDialog').dialog('open');
      alert(returnVal);// RETURNING [object object]
      if(returnVal==true)
      {
        do some thing...
      }
    }

这是我的对话框打开脚本:

  $(function() {
  $('button#btnAdmViewRej').click(function(){
  $('#uploadMsrDialog').dialog('open');
 });
$('#uploadMsrDialog').dialog({
    autoOpen: false,
    width: 250,
    height: 200,
    position: 'top',
    modal: true,
    resizable: false,
    buttons: {
               "OK":function()
                 {
                    callback(true);
                 });
                     $(this).dialog("close");
                 },
                   "Close": function() {
                    callback(false);
                 $(this).dialog("close");
                }
    } //end of buttons:
    });

function callback(val)
{
  return val;
}

1 个答案:

答案 0 :(得分:2)

function someFunction()
{
  var returnVal=$('#uploadMsrDialog').dialog('open');
  /* 
  returnVal is a jquery wrapper object $('#uploadMsrDialog').
  At this point the dialog is shown and is waiting for
  the user to click OK or Close. The execution continues and 
  someFunction exits. callback function has not 
  executed yet. 
  */
}

取决于用户点击的内容(确定或关闭)的逻辑应该在callback中:

function callback(val)
{
  if(val)
  {
    do some thing...
  }
}