问题
How can I use a custom CSS class for the error messages? I'd rather not style the standard label.error. I want to use a CSS class I already have.
回答1:
There is an option for jQuery Validate called errorClass:
Use this class to create error labels, to look for existing error labels and to add it to invalid elements.
All you need to do is specify it in your original $.validate call:
$('#myForm').validate({
errorClass:'myClass'
//your options
});
回答2:
You could do something like that:
html:
<form action="">
<ul>
<li><input type="text" id="name" value="Your name" /></li>
<li><input type="submit" id="submit" /></li>
<li class="error">
<span>Ops!</span>
</li>
</ul>
</form>
css:
form .error {display:none;}
jquery:
$('form').submit(function(){
if($('#name').val()==''||$('#name').val()=='Your name'){
$('form .error').css({display: 'block'});
}
})
来源:https://stackoverflow.com/questions/14447295/using-custom-css-with-jquery-validation