繁体   English   中英

从jquery模型确认或模型对话框返回值

[英]Return value from jquery model confirm or model dialog box

我有一个像这样的JavaScript函数:

使用Javascript:

function dailog_box(){
    $( "#dialog-confirm" ).dialog({
        resizable: false,
        modal: true,
        buttons: {
            Ok: function() {
            $( this ).dialog( "close" );
            return true;   //i want to return value here
        },
            Cancel: function() {
            $( this ).dialog( "close" );
            return false;  //i want to return value here
            }
        }
    });
}

HTML

<div id="dialog-confirm" title="Prescriptions" style="display:none;">
    <p>
        <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
        These items will be permanently deleted and cannot be recovered. Are you sure?<br/>
        <input type="checkbox" name="check_od" id="check_od"/> The prescription is correct;
    </p>
</div>

在调用dialog_box()函数后,我希望变量标志中返回的值,我喜欢这样:

使用Javascript

 var flag = dailog_box();
 alert(flag);

但结果未定义。 并且在我点击任何按钮之前发生警报。 那么在模型按钮中单击任何按钮后,我该怎么做才能获得该值

有关详细信息,请查看http://jsfiddle.net/8e388/13/我希望提醒返回的值。 顺便说一下我对jsfiddle的新手。

你无法完全按照自己的意愿拥有它。 您可以使用其他方式执行此操作:

看看我的小提琴

基本上我有一个全局变量feedback

var feedback = false;

okcancel对话框时,我设置了适当的值。 IMO为您的代码增加了一些灵活性

我建议你使用callback

buttons: {
            Ok: function() {
            callbackSuccess();
            $( this ).dialog( "close" );
        },
            Cancel: function() {
            callbackCancel();
            $( this ).dialog( "close" );
            }
        }

callbackSuccesscallbackCancel - 是一个简单的函数

如果为ConfirmDialog创建帮助程序,则更容易传递回调

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM