gpt4 book ai didi

jquery - 仅在 jQuery 验证插件中为错误消息的元素自定义类

转载 作者:行者123 更新时间:2023-11-28 05:50:03 25 4
gpt4 key购买 nike

在 jQuery Validate 插件中,设置 errorClass 会同时设置错误消息和输入元素的类。无论如何只能为错误消息元素设置类?

最佳答案

不,插件动态地将 errorClass 添加到输入和错误消息元素并且您不能更改此行为,也不需要更改它。毕竟,在您创建一些以它们为目标的 CSS 属性之前,在元素上设置类不会起任何作用。

因此,通过使用正确的 CSS 选择器,您可以轻松地分别定位这些元素。

验证消息的默认 label 容器以及默认 errorClass 设置,即 "error"...

label.error {
/* CSS properties targeting only the error messages */
}

select.error,
textarea.error,
input[type="text"].error,
input[type="radio"].error,
input[type="checkbox"].error {
/* CSS properties targeting only the input elements */
}

演示:http://jsfiddle.net/j3te0d10/


Is there anyway to set class for error message element only?

您永远不需要这样做。

只需在您的 CSS 中定位 label.error,只有错误消息会受到影响。

label.error {
/* CSS properties targeting only the error messages */
}

演示 2:http://jsfiddle.net/j3te0d10/1/

关于jquery - 仅在 jQuery 验证插件中为错误消息的元素自定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37388861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com