Javascript 使用jquery单独验证两个表单

Javascript 使用jquery单独验证两个表单,javascript,jquery,Javascript,Jquery,我在一个页面中有两个表单,我想根据用户填写的内容分别验证每个表单。因此,基本上用户必须只填写一张表单,而不是两张表单……因此,基本上,如果用户填写1号表单,验证将仅在表单1上进行 以下是两种表格的代码: <form action="/registration.flow" method="post" id="formElem1" name="formElem1" autocomplete='off'> <label for="Name_First">Firs

我在一个页面中有两个表单,我想根据用户填写的内容分别验证每个表单。因此,基本上用户必须只填写一张表单,而不是两张表单……因此,基本上,如果用户填写1号表单,验证将仅在表单1上进行

以下是两种表格的代码:

    <form action="/registration.flow" method="post"  id="formElem1"  name="formElem1" autocomplete='off'>
  <label for="Name_First">First Name:</label>
  <input type="text" name="Name_First" id="Name_First" value="" class="required" maxlength="128"  />
  <label for="Name_Last">Last Name:</label>
  <input type="text" name="Name_Last" id="Name_Last" value="" class="required" maxlength="128" />

  <button id="registerButton" type="submit">Register</button>
</form>


<form action="/registration.flow" method="post"  id="formElem2"  name="formElem2" autocomplete='off'>
  <label for="Name_First">First Name:</label>
  <input type="text" name="Name_First" id="Name_First" value="" class="required" maxlength="128"  />
  <label for="Name_Last">Last Name:</label>
  <input type="text" name="Name_Last" id="Name_Last" value="" class="required" maxlength="128" />

   <button id="registerButton" type="submit">Register</button>
</form>

名字:
姓氏:
登记
名字:
姓氏:
登记

有人能帮我吗?

您不需要jQuery专门完成这项工作。简单的javascript很好。为每个表单的onSubmit调用单独的函数

onSubmit="return validateForm1(this);"
  • 及-

    onSubmit=“return validateForm2(this);”

请确保返回true或false,具体取决于表单是否通过了验证。

我建议您选择。它易于使用,您可以分别执行这两个验证