jquery - 如果我在验证电子邮件时收到错误,请重新加载表单
问题描述
我在 .html 文件中有这样的表格:
<body>
<script>
$(document).ready(function(){
$("#submit").click(function(){
if($("#mail").val() != $("#rmail").val()){
alert("emails don't match");
//?
}
});
});
</script>
<form action="action.php" method="POST">
<p>E-mail:</p>
<input type = "email" id="mail" name = "correo">
<p>Repetir e-mail:</p>
<input type = "email" id="rmail" name = "rcorreo">
<input id="submit" type="submit"/>
</form>
</body>
如果邮件不匹配,J-Query 函数会显示警报,然后转到 action.php 页面
如果邮件不匹配,我想要做的是重新加载表单并防止进入 action.php 页面。我试过评论location.reload();
在哪里,//?
但它不起作用。
有什么线索吗?提前致谢。
解决方案
<body>
<script>
$(document).ready(function(){
$("#submit").click(function(event){
if($("#mail").val() != $("#rmail").val()){
event.preventDefault();
alert("emails don't match");
window.location.reload();
}
});
});
</script>
我希望这会有所帮助
推荐阅读
- ssh - 复制 ssh 私钥文件
- javascript - 用 jest 在 JS/Vue 中测试黑盒 API
- python - 如何用 folium 绘制地图并在 python 中的地图旁边放置条形图?
- selenium - 我在 stepDefinition 收到 java.lang.NullPointerException
- python - 是否可以通过 Id 循环并在内部执行操作?
- ssh - gcloud 计算——忽略了实例 ssh-key 元数据?
- java - 空对象的默认 hashCode
- c# - 如何从孩子更新 MDI 表单中的工具条进度条?
- python - 如何使用 BeautifulSoup 抓取非 HTML 标签
- rest - 如何使用 odoo 12 调用和读取 API REST(从我的应用程序到 odoo)