我使用了jQuery Confirm plugin。在我的情况下,jQuery Confirm运行良好。
但我的问题是如何从我的jconfirm
函数中获取返回值。
这里我想将jconfirm
函数的结果保存到confirmVar中,然后根据条件进行检查,根据条件进行一些工作。但是这里confirmVar
无法获得jconfirm
函数的返回值。
if (courseCredit > remainingCredit) {
//Here confirmVar cant get the return value.
var confirmVar = jconfirm({
theme: 'black',
title: 'Course Credit Confirmation',
content: 'Are you sure to take this Course ?',
confirmButton: 'Yes',
cancelButton: 'NO'
});
//Here I want to check confirmVar
if (confirmVar==true) {
$.ajax({
url: "@Url.Action("AssignCourse", "CourseTeacher")",
type: "POST",
data: { courseTeacher: [deptCode, tchrMail, creditToTake, remainingCredit, courseCode, crseTchrName, courseCredit] },
console: log(data),
dataType: "json",
success: function (data) {
}
});
}
else if(confirmVar == false) {
//do nothing
}
return false;
}

答案 0 :(得分:0)
你可以使用类似的东西;
var choose=false;
$.confirm({
theme: 'black',
title: 'Course Credit Confirmation',
content: 'Are you sure to take this Course ?',
confirmButton: 'Yes',
cancelButton: 'NO'
confirm: function(){
choose=true;
},
cancel: function(){
choose=false;
}
});
在javascript的根级别定义变量,并使用confirm
或cancel
状态进行更改。希望这对你有用。
更新
$.confirm({
theme: 'black',
title: 'Course Credit Confirmation',
content: 'Are you sure to take this Course ?',
confirmButton: 'Yes',
cancelButton: 'NO'
confirm: function(){
$.ajax({
url: "@Url.Action("AssignCourse", "CourseTeacher")",
type: "POST",
data: { courseTeacher: [deptCode, tchrMail, creditToTake, remainingCredit, courseCode, crseTchrName, courseCredit] },
console: log(data),
dataType: "json",
success: function (data) { }
});
},
cancel: function(){
//do nothing
}
});