我正在使用 jQuery 验证插件进行“实时”表单验证。我试图不显示出现的错误消息,因为它会影响布局等。
它会生成一个标签,弄乱我在页面上的样式,是否有可能根本不显示?
// the label it generates for an error
<label for="address_1" class="error">Please enter at least 2 characters.</label>
$('#checkout-form').validate({
rules: {
first_name: {
minlength: 2,
required: true
},
last_name: {
minlength: 2,
required: true
}
},
highlight: function (element) {
$(element).addClass('#error')
.closest('.form-group').removeClass('valid');
},
success: function (element) {
element.addClass('valid')
.closest('.form-group').removeClass('error');
}
});
// custom css
<style type="text/css">
label.valid {
position: relative;
top: -25px;
right: 10px;
float: right;
width: 16px;
height: 16px;
background: url('/assets/images/icons/tick.png') center center no-repeat;
display: inline-block;
text-indent: -9999px;
}
label.nonvalid {
position: relative;
top: -25px;
right: 10px;
float: right;
width: 16px;
height: 16px;
background: url('/assets/images/icons/cross.png') center center no-repeat;
display: inline-block;
text-indent: -9999px;
}