[英]How can I get my partial view alert to fire before the parent page is submitted?
I have a partial view with a submit button on it. 我有一个局部视图,上面有一个提交按钮。 I want to send an alert fire an alert when the button is clicked.
单击按钮后,我想发送警报。 If I remove the line…
如果我删除线…
return false; 返回false;
The page is submitted and the alert will fire after the page is submitted. 该页面已提交,提交页面后将触发警报。 If I leave 'return false' in the if statement the page won't submit the alert wont fire either.
如果我在if语句中保留“ return false”,则该页面也不会提交警报,也不会触发。 How can I get my partial view alert to fire before the parent page is submitted?
如何在提交父页面之前触发我的局部视图警报?
Here's my code: 这是我的代码:
<script type="text/javascript">
$(function () {
var selectedName = $("#selectAname");
$("#sendMail").click(function () {
if (selectedName.val() == "Worng Choice")
alert("You need to select the correct name")
return false;
});
});
Thanks for any suggestions! 感谢您的任何建议!
If I understand you right, you want to fire an alert on wrong choice and cancel submitting the form, you need to move return false
into block with if (wrong choice): 如果我理解的正确,那么您想对错误的选择发出警报并取消提交表单,您需要将
return false
移至带有if(错误选择)的块中:
$(function () {
var selectedName = $("#selectAname");
$("#sendMail").click(function () {
if (selectedName.val() == "Worng Choice") {
alert("You need to select the correct name");
return false;
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.