【发布时间】:2014-03-06 19:21:44
【问题描述】:
您好,我正在尝试让确认对话框 (Bootbox) 工作。它显示确认对话框,但在按下确定按钮时不执行任何操作。
$(document).on("click", "#close", function (e) {
e.preventDefault();
var $this = $(this);
bootbox.confirm("Are you sure you want to close this Service Request? This operation cannot be reversed."
, function (result) {
if (result) {
$this.closest('form').submit();
} else {
console.log("user declined");
}
});
});
我认为这是错误的:
$this.closest('form').submit();
我的按钮是<td><a href="@Url.Action("CloseLog", "Log", new {id = item.LogID})"><span class="glyphicon glyphicon-trash" id="close"></span></a>
问题是如何让确定按钮工作?
编辑: 我可以从按钮中的 onClick 调用此函数吗?如果有怎么办?
$(document).on("click", ".alert", function (e) {
var link = $(this).attr("href"); // "get" the intended link in a var
e.preventDefault();
bootbox.confirm("Are you sure?", function (result) {
if (result) {
document.location.href = link; // if result, "set" the document location
}
});
});
【问题讨论】:
-
你的意思是按ok后什么都没有发生吗?
-
完全正确。什么都没有发生
-
$ 是一个元符号,不要将它用作变量名的一部分,试试 $(this).closest('form').submit();
-
请看我的问题编辑@VladL
-
或者我将如何使用它?
标签: javascript jquery asp.net asp.net-mvc bootbox