jQuery Modal弹出对话框ok按钮单击事件

时间:2014-05-05 14:22:21

标签: jquery jquery-ui-dialog

我正在尝试打开对话框并在辅助函数中传递OK回调函数。所以单击Ok按钮,该功能将执行。 但问题是,在对话函数调用时执行回调函数。以下是我的代码。

  function ModelMessage(message, title, messageType, okButtonText, okCallBack) { 
$("#dialog-confirm").dialog({
        resizable: false,
        height: 200,
        modal: true,
        open: function (event, ui) {            
            $('.ui-button-text').each(function (i) {
                $(this).html($(this).parent().attr('text'));
            });                
        },
        buttons: [{
            text: "Ok",
            id : "btnModalDialog",
            Click : function () {                    
                okCallBack();                   
                $("#dialog-confirm").dialog("close");
            }
        }]
    });

以下是我调用此辅助函数的代码:

ModelMessage(ProjectSaveSuccess, null, null, "Ok", function () {
                                window.location.href = url_CreateProject + "?projectID=" + PID.val();
                            });

我正在使用jquery-1.9.1.js和jquery-ui.js(1.9.1)。 此问题在旧版本的jquery中无法复制。这个jquery是否已知错误?

2 个答案:

答案 0 :(得分:1)

我可以肯定地说这是jquery 1.9.1的错误。以下是我所做的黑客暨解决方案。

在按钮声明中我已经把条件 - 当对话框打开然后只执行按钮回调函数。请看下面的按钮declration。

buttons: [{
            text: "Ok",
            id : "btnModalDialog",
            Click : function () {                    
                var isOpen = $("#dialog-confirm").dialog("isOpen");
                    if (isOpen == true) {
                    okCallBack();
               }
                $("#dialog-confirm").dialog("close");
            }
        }]

答案 1 :(得分:0)

我认为你对«按钮»属性执行不好。试试这个:

 $("#dialog-confirm").dialog({
    resizable: false,
    height: 200,
    modal: true,
    open: function (event, ui) {            
        $('.ui-button-text').each(function (i) {
            $(this).html($(this).parent().attr('text'));
        });                
    },
    buttons: [{
         Ok: function() {
             okCallBack();
             $(this).dialog("close");
         }
    }]
});
相关问题