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

How to pass the return value of jquery dialogue box button function in some called function

本文关键字:函数 jquery 对话框 按钮 返回值 调用      更新时间:2023-09-26

我想获得jquery对话框的返回值,取决于对话框的返回值是真还是假,我需要调用一些其他函数,这里是我的试验,但这里是返回[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;
}
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. 
  */
}

依赖于用户点击的内容(OK或Close)的逻辑应该在callback:

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