我有一些验证,但需要隐藏 div 错误,或者在成功时添加“隐藏”类。我已经包含了我正在使用的插件的链接。您可以在我的演示中看到,当您填写一个字段时,每个输入下方的错误标签都会添加一个空格。http://cuberocigars.com/bugler/xml.request.php
HTML
<div class="control-group">
<div class="controls">
<input type="text" class="input-coupon" name="address1" placeholder="Street Address" id="address1">
</div>
</div>
JS - 这是亮点和成功
$(document).ready(function(){
// Validate
// http://bassistance.de/jquery-plugins/jquery-plugin-validation/
// http://docs.jquery.com/Plugins/Validation/
// http://docs.jquery.com/Plugins/Validation/validate#toptions
$('#contact-form').validate({
rules: {
address1: {
minlength: 2,
required: true
}
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function(element) {
element
.closest('.control-group').removeClass('error').addClass('success')
}
});
}); // end document.ready
CSS
label.error {
font-weight: bold;
color: red;
padding: 2px 8px;
margin-top: 2px;
}