jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery验证元素背景的变化颜色大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
认情况下,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>

输入元素在错误时给出jqInvalid错误类.

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;}

解决方法

无效元素得到一个错误by default,或者在你的情况下jqInvalid,因为你已经设置了errorClass选项,只需在样式表中设置你想要的类,例如:
.jqInvalid { BACkground: #ffdddd; }

如果需要,您可以覆盖错误消息的详细信息(认元素为< label>):

label.jqInvalid { BACkground: none; }

这种CSS方法负责@L_673_20@…因为类一旦有效就被@L_673_20@.如果您想要将绿色背景应用于有效元素等,那么还有一个成功类.

大佬总结

以上是大佬教程为你收集整理的jQuery验证元素背景的变化颜色全部内容,希望文章能够帮你解决jQuery验证元素背景的变化颜色所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。