【发布时间】:2015-08-28 16:20:12
【问题描述】:
我的 ASP.Net MVC 5 Razor 视图中有一个按钮
@using (Html.BeginForm("MyAction", "MyController", FormMethod.Post, new { id = "myForm" }))
{
<button type="submit" class="btn btn_d fl sepV_a" id="btnNotify" name="btnNotify"><span>Notify</span></button>
}
当它被点击时,我会调用一个 JQuery 函数来询问用户是否仍希望继续提交
<script type="text/javascript">
$(document).ready(function () {
$("#btnNotify").click(ConfirmNotify);
function ConfirmNotify() {
if (confirm('Are you sure you wish to continue?')) {
$("#btnNotify").attr('disabled', 'disabled');
return true;
} else {
return false;
}
}
});
</script>
如果用户单击“确定”以确认提交,那么我想禁用“通知”按钮。
不幸的是,当用户单击“确定”出现提示时,上面的代码禁用了“通知”按钮,但是,随后不会出现“提交”表单。
如果我将$("#btnNotify").attr('disabled', 'disabled'); 和return true; 换成这样
function ConfirmNotify() {
if (confirm('Are you sure you wish to continue?')) {
return true;
$("#btnNotify").attr('disabled', 'disabled');
} else {
return false;
}
}
当用户单击“确定”时,表单被提交,但“通知”按钮并未被禁用,即用户可以多次单击“通知”按钮。
有谁知道如何纠正这个问题?非常感谢任何建议。
谢谢。
【问题讨论】:
-
无论你在哪里调用这个函数'ConfirmNotify',在这个函数被调用后让通知按钮失效。
标签: jquery form-submit disabled-input