jConfirm警报-jQuery插件 [英] jConfirm alert - jQuery plugin
问题描述
是jConfirm,用于用户确认.
Am jConfirm for user confirmation.
我的第一个jConfirm不会停止用户的操作,而只是传递到下一个.
My first jConfirm doesnt stop for user action and just passes to next.
我的代码:
$(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;
}
});
}
});
}
}
});
});
});
我想念什么?
推荐答案
不确定是否全部,但这部分是
Not sure if this is all, but this part:
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (!ans)
return;
});
}
可能没有执行您想要的操作.它可能正在退出function(ans) { ... }
函数,而您可能想退出整个处理程序,即$("#UpdateJobHandler").click(function () { ... }
.如果是这样,您将需要执行与以下操作类似的操作,即将整个内容放在返回后的function(ans) { ... }
中.最好将其分解为较小的功能.
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 afterContinue() {
var json = $.toJSON(JobHander);
$.ajax({
// ... all other lines here ...
});
}
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (ans) {
afterContinue();
}
});
}
您可以对所有success
功能执行类似的操作.
You can do similar thing for all the success
functions.
另一个例子,您可以像这样重写Instances
检查:
Another example, you can rewrite the Instances
check like this:
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();
}
});
}
重要-将方法(afterContinue
,afterInstances
,...)重命名为具有某些名称,这对于将来阅读此内容的人来说是有用的.
Important - rename the methods (afterContinue
, afterInstances
, ...) to have some name that means something useful to someone reading this in the future.
这篇关于jConfirm警报-jQuery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!