默认情况下,jQuery.validate似乎不会更改无效元素的背景颜色.是否也可以更改选择元素的背景颜色?我的大多数元素都是输入类型=“文本”,但我需要一个选择表单元素的指标.我没有使用默认生成的消息,因为它们不适合我的布局.
以下代码确实更改了输入元素的背景颜色,但它永远不会恢复为以前的样式:
$('form[name="register"]').validate({ errorClass: 'jqInvalid',rules: { fnameCreate: "required",//input monthCreate: "required",//select emailCreate: { required: true,email: true },//input passwordCreate: "required",//input type=password },messages: { fnameCreate: "",monthCreate: "",emailCreate: "",passwordCreate: "",},errorPlacement: function (error,element) { element.css('background','#ffdddd'); } });
编辑(样本)
<div class="field"> <div class="labelName_fb"> <label for="email">Email</label> </div> <div class="divforText3"> <div class="divLeft"></div> <div class="textBox-image3"> <input class="txt required" id="emailCreate" name="emailCreate" value="" maxlength="100" type="text" style='width:180px'> </div> <div class="divright"></div> </div> </div>
CSS
/* line 3 */ .error { background: #ffdddd; } /* I have since removed the errorClass option */ /* line 254 */ .field .txt {background:transparent none repeat scroll 0 0;border:medium none;color:#000;font-size:11px;width:130px; margin:5px 0;}