我在登录时出现登录对话框时遇到了困难。我需要发生的是,当用户使用内置的 MVC3 身份验证控件登录时,我需要它弹出一个对话框,其中列出一些条款和协议(protocol),并说“如果您点击接受,则表示您同意上述内容”。我目前有这个,但是当我点击取消时,该网站仍然会登录。这是我的代码:
<fieldset>
<legend>Login</legend>
<div class="editor-label">
@Html.LabelFor(model => model.userName)
</div>
<div class="focus">
<div class="editor-field">
@Html.EditorFor(model => model.userName)
</div>
</div>
<div class="editor-label">
@Html.LabelFor(model => model.passWord)
</div>
<div class="editor-field">
@Html.PasswordFor(model => model.passWord)
</div>
<p>
<input type="submit" value="Login" name="btnLogin" id="btnLogin" />
</p>
@Html.ValidationSummary(true)
</fieldset>
还有我拥有的 Javascript:
<script type="text/javascript">
$(function () {
$("#btnLogin").click(function () {
var answer = confirm("Unauthorized access or use of the web content is prohibited.\n" + "By clicking 'OK', you have agreed to the above conditions");
if (answer) {
}
else {
$(this).dialog("close");
}
});
});
</script>
当用户在对话框中点击“取消”时,我如何才能取消登录时的 HttpPost,并在点击“确定”时继续登录?
非常感谢!!
最佳答案
在你的事件处理程序中添加这个
$("#btnLogin").click(function (event) {
var answer = confirm("Unauthorized access or use of the web content is prohibited.\n" + "By clicking 'OK', you have agreed to the above conditions");
if (answer) {
}
else{
$(this).dialog("close");
event.preventDefault();
}
});
添加 event.preventDefault();
确保防止表单的默认行为
关于javascript - “你接受条款和条件吗?”关于登录表单例份验证 MVC3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10721727/