jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用jqueryUI对话框模仿confirm()大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用jQueryUI对话框模仿标准的JavaScript confirm().我在虑以下内容,但我显然不明白它应该如何运作.有什么建议么?谢谢
return $("#dialog-cancel").dialog("open");

$("#dialog-cancel").dialog({
    autoOpen: false,height: 400,width: 350,modal: true,open: function(event,ui){},buttons: {'OK': function(){$(this).dialog("close");return true;},'CANCEL': function() {$(this).dialog("close");return false;}}
});

解决方法

副本确实没用.对不起,我很抱歉.

基于这个answer,这就是我要做的:

>创建一个函数,创建一个带有消息和OK / Cancel按钮的基本模态对话框
>为单击它们时执行的两个按钮接受两个回调

好处是它不会像答案那样用无限循环来阻止整个浏览器. jQuery UI对话框的选项模式只是阻止当前页面.

这是@L_673_8@:

function confirmDialog(message,onOK,onCancel) {

    $('<div>' + message + '</div>').dialog({
        modal: true,buttons : {
            "OK" : function() { 
                $(this).dialog("close");

                // if there is a callBACk,execute it
                if (onOK && $.isFunction(onOK)) {
                    onOK();
                }

                // destroy the confirmation dialog
                $(this).dialog("destroy");
            },"Cancel" : function() {
                $(this).dialog("close");
                if (onCancel && $.isFunction(onCancel)) {
                    onCancel();
                }
                $(this).dialog("destroy");
            }
        }
    });

}

你可以这样使用它:

$('button').click(function(E) {

    var okHandler = function() {
        alert('ok');
    };

    confirmDialog('Do you really want ?',okHandler);
});

DEMO

大佬总结

以上是大佬教程为你收集整理的使用jqueryUI对话框模仿confirm()全部内容,希望文章能够帮你解决使用jqueryUI对话框模仿confirm()所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。