当我在我的应用程序中打开弹出窗口时。进行一些更改并关闭它而不保存。它会显示一条确认消息,弹出窗口不会关闭。
var r = confirm("There are some unsaved changes, do you want to quit?");
进一步执行用户确认,Yes or cancel.(Native jquery buttons).
我需要有三个按钮Yes ,No and Cancel
。我这样做了。
var question = "There are some unsaved changes, do you want to quit?";
confirmation(question).then(function (answer) {
// var ansbool = Boolean.parse(answer.toString());
var r = answer.toString();
alert(r);
if (r == "true") {
.....
return true;
}
else {
....
return false;
}
});
function confirmation(question) {
var defer = $.Deferred();
$('<div></div>')
.html(question)
.dialog({
autoOpen: true,
modal: true,
title: 'Confirmation',
buttons: {
"Yes": function () {
defer.resolve("true"); //this text 'true' can be anything. But for this usage, it should be true or false.
$(this).dialog("close");
},
"No": function () {
defer.resolve("false"); //this text 'false' can be anything. But for this usage, it should be true or false.
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
return defer.promise();
};
它显示了包含这三个按钮的消息。但是也关闭了主弹出窗口。当用户点击Yes ,No ,
然后它关闭时我想要它。点击后。
提前致谢。
答案 0 :(得分:0)
这是因为您的确认电话刚刚通过,它不会等待答案。我知道这样做的唯一方法是将操作放在确认中:
UI.confirmDialog('Record will be removed...Continue?').done(function () {
//perform the desired function here
return false;
}).fail(function () {
return false;
});