jQuery验证:如何将字段设为红色 [英] Jquery Validation: How to make fields red
问题描述
我正在使用jquery和jquery.validate.cs(jQuery验证插件1.8.0)来验证表单.现在,它在字段旁边显示一条消息:这是必填字段".
I am using jquery and jquery.validate.cs (jQuery Validation Plugin 1.8.0) to validate a form. Right now it displays a message next to a field saying : "This is a required field".
我还希望每个字段都变成红色.我该怎么办?谢谢!
I also want each field to turn red color. How would i do that? Thanks!
推荐答案
没有任何自定义配置,您可以执行以下操作:
Without any custom configuration, you can just do this:
select.error, textarea.error, input.error {
color:#FF0000;
}
- 应用于无效输入的默认类为
error
- 已验证输入的默认类为
valid
. - The default class that is applied to an invalid input is
error
- The default class for an input that was validated is
valid
.
这些类也适用于错误标签,因此在编写CSS时要注意这一点.
These classes are also applied to the error label, so be aware of that when writing your CSS.
验证插件允许您配置这些类名,因此您可以执行以下操作:
The validation plugin allows you to configure these class names, so you may do something like this:
$("form").validate({
errorClass: "my-error-class",
validClass: "my-valid-class"
});
.my-error-class {
color:#FF0000; /* red */
}
.my-valid-class {
color:#00CC00; /* green */
}
- 带有自定义类的演示: http://jsfiddle.net/wesley_murch/j3ddP/1/
- Demo with custom classes: http://jsfiddle.net/wesley_murch/j3ddP/1/
可以在 http://docs.jquery.com/Plugins/Validation/validate a中找到配置选项>
The configuration options can be found at http://docs.jquery.com/Plugins/Validation/validate
这篇关于jQuery验证:如何将字段设为红色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!