我正在使用jQuery Validate Plugin:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
简单演示:
<input type="text" name="email" class="required email" /> <input type="text" name="email_confirm" class="required email" />
如何检查两个输入中的值是否与jQuery或jQuery Validate Plugin相同.
我只是尝试了相同,它的工作原理:
rules: { email: 'required',email2: {equalTo: '.email'}
解决方法
通过查看
http://jquery.bassistance.de/validate/demo/的演示页面,您可以使用“equalTo”验证两个应该相等的字段:
$("#signupForm").validate({ rules: { ...snip... password: { required: true,minlength: 5 },confirm_password: { required: true,minlength: 5,equalTo: "#password" },...snip... },messages: { ...snip... password: { required: "Please provide a password",minlength: "Your password must be at least 5 characters long" },confirm_password: { required: "Please provide a password",minlength: "Your password must be at least 5 characters long",equalTo: "Please enter the same password as above" },...snip... } });
要使用类方法,只需要找到语法.我找不到equalTo属性,但它可能是这样的:
class="required email equalTo['email']"