I am trying to open dialog box and passing OK callback function in helper function. So on click of Ok button that function will execute. But problem is, callback function getting executed at the time of dialog function call. Below is my code.
我试图打开对话框并在辅助函数中传递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");
}
}]
});
Below is the code from where I am calling this helper function:
下面是我调用这个帮助函数的代码:
ModelMessage(ProjectSaveSuccess, null, null, "Ok", function () {
window.location.href = url_CreateProject + "?projectID=" + PID.val();
});
I am using jquery-1.9.1.js and jquery-ui.js(1.9.1). This issue is not replicate in older version of jquery. Is this jquery known bug?
我使用的是jquery-1.9.1.js和jquery-ui.js(1.9.1)。在旧版本的jquery中不能复制此问题。这个jquery已知错误吗?
2 个解决方案
#1
1
I can surely say that this is bug of jquery 1.9.1. Below is the hack cum solution i have done.
我可以肯定地说这是jquery 1.9.1的错误。以下是我所做的黑客暨解决方案。
In button declaration I have put condition-when dialog box is open then only button callback function execute. Look at the below button declration.
在按钮声明中我已经把条件 - 当对话框打开然后只有按钮回调函数执行。看下面的按钮declration。
buttons: [{
text: "Ok",
id : "btnModalDialog",
Click : function () {
var isOpen = $("#dialog-confirm").dialog("isOpen");
if (isOpen == true) {
okCallBack();
}
$("#dialog-confirm").dialog("close");
}
}]
#2
0
I think you did a bad implementation of the «buttons» property. Try this :
我认为你对«按钮»属性执行不好。尝试这个 :
$("#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");
}
}]
});
#1
1
I can surely say that this is bug of jquery 1.9.1. Below is the hack cum solution i have done.
我可以肯定地说这是jquery 1.9.1的错误。以下是我所做的黑客暨解决方案。
In button declaration I have put condition-when dialog box is open then only button callback function execute. Look at the below button declration.
在按钮声明中我已经把条件 - 当对话框打开然后只有按钮回调函数执行。看下面的按钮declration。
buttons: [{
text: "Ok",
id : "btnModalDialog",
Click : function () {
var isOpen = $("#dialog-confirm").dialog("isOpen");
if (isOpen == true) {
okCallBack();
}
$("#dialog-confirm").dialog("close");
}
}]
#2
0
I think you did a bad implementation of the «buttons» property. Try this :
我认为你对«按钮»属性执行不好。尝试这个 :
$("#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");
}
}]
});