jConfirm 警报 - jQuery 插件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4373331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jConfirm alert - jQuery plugin
提问by Sreedhar
Am jConfirm for user confirmation.
Am jConfirm 用于用户确认。
My first jConfirm doesnt stop for user action and just passes to next.
我的第一个 jConfirm 不会因用户操作而停止,而是传递给下一个。
My Code:
我的代码:
$(function () {
$("#UpdateJobHandler").click(function () {
var JobHander = getJobHandler();
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (!ans)
return;
});
}
var json = $.toJSON(JobHander);
$.ajax({
url: '../Metadata/JobHandlerUpdate',
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
var message = data.Message;
var alertM = data.MessageType;
if (alertM == 'Error') {
$("#resultMessage").html(message);
}
if (alertM == 'Success') {
$("#resultMessage").empty();
alert(alertM + '-' + message);
action = "JobHandler";
controller = "MetaData";
loc = "../" + controller + "/" + action;
window.location = loc;
}
if (alertM == "Instances") {
jConfirm(message, 'Instances Confirmation?', function (answer) {
if (!answer)
return;
else {
var JobHandlerNew = getJobHandler();
JobHandlerNew.FinalUpdate = "Yes";
var json = $.toJSON(JobHandlerNew);
$.ajax({
url: '../Metadata/JobHandlerUpdate',
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
var message = data.Message;
$("#resultMessage").empty();
alert(alertM + '-' + message);
action = "JobHandler";
controller = "MetaData";
loc = "../" + controller + "/" + action;
window.location = loc;
}
});
}
});
}
}
});
});
});
What am i missing?
我错过了什么?
回答by icyrock.com
Not sure if this is all, but this part:
不确定这是否是全部,但这一部分:
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (!ans)
return;
});
}
probably doesn't do what you want. It is exiting the function(ans) { ... }
function, while you probably want to exit the whole handler, i.e. $("#UpdateJobHandler").click(function () { ... }
. If so, you would need to do similar to what you do below - i.e. put the whole thing in function(ans) { ... }
, after the return. Probably best to separate into smaller functions.
可能不会做你想做的。它正在退出function(ans) { ... }
函数,而您可能想要退出整个处理程序,即$("#UpdateJobHandler").click(function () { ... }
. 如果是这样,您将需要执行类似于您在下面所做的操作 - 即function(ans) { ... }
在返回后将整个内容放入 中。可能最好分成更小的功能。
EDIT: Something along these lines:
编辑:沿着这些路线的东西:
function afterContinue() {
var json = $.toJSON(JobHander);
$.ajax({
// ... all other lines here ...
});
}
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (ans) {
afterContinue();
}
});
}
You can do similar thing for all the success
functions.
您可以为所有success
功能做类似的事情。
Another example, you can rewrite the Instances
check like this:
另一个例子,你可以Instances
像这样重写支票:
function afterInstances() {
var JobHandlerNew = getJobHandler();
JobHandlerNew.FinalUpdate = "Yes";
// ... and everything under else branch ...
}
if (alertM == "Instances") {
jConfirm(message, 'Instances Confirmation?', function (answer) {
if (answer) {
afterInstances();
}
});
}
Important - rename the methods (afterContinue
, afterInstances
, ...) to have some name that means something useful to someone reading this in the future.
重要 - 重命名方法 ( afterContinue
, afterInstances
, ...) 以具有一些对将来阅读本文的人有用的名称。