[英]separate validation of two forms with jquery
我在一个页面中有两个表单,我想分别验证每个表单依赖于用户填写的内容。 所以基本上用户必须只填写一个表格而不是两个表格......所以基本上如果用户填写表格编号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,具体取决于表单是否通过验证或验证失败。
我建议你使用jquery验证器 。 它易于使用,您可以单独进行两次验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.