小提琴更新:我没有很好地解释它,所以我会解释我想要做什么。 我不是要尝试表单验证,我已经通过HTML 5" required"领域。 我想要做的是能够控制" .error"的样式。当用户无法输入字段或提供无效信息时,由jQuery填充。如何控制样式是不是由jQuery验证函数填充?
FIDDLE:http://jsfiddle.net/xvAPY/140/
$('#contactForm').validate({ // initialize the plugin
errorElement: 'div',
rules: {
first_name: {
required: true,
},
last_name: {
required: true,
}
postal_code: {
required: true,
},
phone_primary: {
required: true,
}
email: {
required: true,
}
},
submitHandler: function(form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
<form id="contactForm" method="POST" action="https://app.leadconduit.com/v2/PostLeadAction">
<input type="text" id="first_name" name="first_name" minlength="5" maxlength="255" placeholder="First Name" required />
<input type="text" id="last_name" name="last_name" minlength="2" maxlength="255" placeholder="Last Name" required />
<input type="hidden" id="state" name="state" value="" />
<input type="text" id="postal_code" name="postal_code" minlength="5" maxlength="10" placeholder="Zip Code" required />
<input type="text" id="phone_primary" name="phone_primary" minlength="11" maxlength="12" placeholder="Phone" required />
<input type="text" id="email" name="email" minlength="25" maxlength="255" placeholder="Email" required />
<input type="submit" value="Submit"/>
答案 0 :(得分:1)
您的代码有语法错误
Uncaught SyntaxError: Unexpected identifier
并且正在进行的验证是html5验证。
last_name: {
required: true,
} <----------------- no comma ----
postal_code: {
required: true,
},