如果验证电子邮件时出现错误,请重新加载表格

时间:2019-05-15 14:55:43

标签: jquery html forms

.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();注释的//?处使用,但它不起作用。

有任何线索吗?预先感谢。

1 个答案:

答案 0 :(得分:2)

<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>

我希望这会有所帮助