【发布时间】:2015-05-06 21:10:38
【问题描述】:
我正在尝试根据 jQuery 对话框选择返回结果。在发送退货声明之前,我一直保持警报消息。如何保持结果返回,直到我在对话框中做某事?值将是“真”或“假”
function ConfirmDone() {
var results;
$('<div></div>').appendTo('body')
.html('<div><h6>Are you sure you want to lose unsaved changes?</h6></div>')
.dialog({
modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
Yes: function () {
$(this).dialog("close");
results=true;
},
No: function () {
$(this).dialog("close");
results=false;
}
},
close: function (event, ui) {
$(this).remove();
results = false;
}
});
alert(results); //This is calling same when dialog shows up
return results;
}
这里有什么问题?
更新:
我不确定。回调函数可以应用于我的代码吗?正如@Barmar 在重复帖子中提到的那样
更新
@Ajax.ActionLink(
new { CommunicationLocation = commemail.Location, CommunicationType = "email" },
new AjaxOptions()
{
HttpMethod = "Post",
UpdateTargetId = "DivEmailContainer",
InsertionMode = InsertionMode.Replace,
OnBegin = "return ConfirmDone(function(success) {alert('You said: ' + (success ? 'Yes' : 'No'))});"
},
new { @class = "linkbutton" })
}
$(document).ready(function () {
$("#deletedialog").dialog({
autoOpen: false,
modal: true
});
});
function ConfirmDone(callback) {
$("#deletedialog").dialog({
buttons: {
"Delete":{ text: "Delete",
class: "btn btn-success",
click: function () {
$(this).dialog("close");
callback(true);
}
},
"Cancel": {
text: "Cancel",
class: "linkbutton",
click: function () {
$(this).dialog("close");
callback(false);
}
}
}
});
$("#deletedialog").dialog("open");
【问题讨论】:
-
@Barmar,我不明白重复的帖子会适用于我的代码吗?我很困惑。
-
对不起,复制的选择很糟糕,因为它使用了不同的插件。但总体思路是对话是异步的。你的
ComfirmDone函数应该接受一个回调参数,并在close:函数中调用它。 -
有人帮忙,还有其他选择吗?
-
也许此搜索中的一个问题会有所帮助:stackoverflow.com/…
标签: javascript jquery asp.net-mvc asp.net-mvc-4 jquery-ui