jQuery验证在检查后不会提交

时间:2017-09-21 04:33:01

标签: javascript jquery validation

我正在尝试创建一个使用jQuery validate插件验证的表单。 我已经成功实现了验证,因此它会检查我希望它的表单区域,但是现在表单在填写表单输入区域时不会提交。有人可以提供一些建议,告诉我如何能够一旦确认就提交。

也没有必要,但是我会希望错误消息标签显示在表单区域的右侧或底部。这是我的代码,任何建议将不胜感激PS我很抱歉格式不好。

g(a) = f(a)

2 个答案:

答案 0 :(得分:0)

通过在debug : true中设置jQuery.validator.setDefaults,您正在告诉您要调试的jquery validate插件,并且不希望立即提交表单。

debug设为false

同时从return validate()

中删除onsumbit

答案 1 :(得分:0)

正常工作,只需从表单中删除onsubmit="return validate();"

jQuery.validator.setDefaults({
  debug: true,
  success: "valid",
  submitHandler: function() {
    alert("submitted!");
  }
});
$("#myform").validate({
  rules: {
    chkbox: {
      required: true,
    },
    Fname: "required",
    Lname: "required",
    Phone: "required",
    Address: "required",
    email: {
      required: true,
      email: true
    },

  },
  messages: {
    Fname: "Please enter your firstname",
    Lname: "Please enter your lastname",
    Phone: "Please enter your phone number",
    email: "Please enter a valid email address"

  }
});
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js">
</script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-
methods.min.js"></script>

<!------- Web page Content ------>


<div id="content">


  <h2> Register with GTB Financial Solutions </h2>

  <form method="post" action="post-test.php" id="myform" name="myform" >

    How to maximise profits on managed funds<input type="checkbox" name="chkbox"><br> Minimising tax in the new environment<input type="checkbox" name="chkbox"><br> Measuring stock momentum<input type="checkbox" name="chkbox"><br> Economic forecasts
    <input
      type="checkbox" name="chkbox"><br> Creative accounting for management<input type="checkbox" name="chkbox"><br> The exciting new features of the ATO web site<input type="checkbox" name="chkbox"><br><br>
      <label for="Fname">First Name</label><br>
      <input type="text" name="Fname" id="Fname"><br>
      <label for="Lname">Last Name</label><br>
      <input type="text" name="Lname" id="Lname"><br>
      <label for="Phone">Phone Number</label><br>
      <input type="text" name="Phone" id="Phone"><br>
      <label for="E-mail">E-mail Address</label><br>
      <input type="email" name="email" id="email"><br>
      <label for="Address">Address</label><br>
      <input type="text" name="Address" id="Address"><br>

      <input type="submit" value="submit">
  </form>

</div>