CSS selectors - how to select #39;for#39; in CSS?(CSS 选择器 - 如何在 CSS 中选择“for?)
问题描述
我正在使用 jQuery 验证.
I'm using jQuery validation.
当 for 现在有效时,验证器正在创建这些:
When for is now valid, validator is creating those:
<label class="error" for="username" generated="true">
由于所有标签都具有相同的 class=error,我可以根据 'for' 使用 CSS 选择这个确切的标签吗?
As all label has got the same class=error can I select with CSS this exact one based on 'for'?
我知道如何用 jQuery 来解决这个问题——但总是在寻找最干净、最纯粹的方式.任何建议都非常感谢.
I know how to sort this out with jQuery - but always looking for cleanest, purest way. Any suggestion much appreciated.
皮特
推荐答案
使用 (CSS2) 属性选择器:
Using the (CSS2) attribute selector:
.error[for="username"]
这适用于 IE8+ 和所有现代浏览器.
This will work in IE8+ and all modern browsers.
IE7 的属性选择器有问题:如此处所述,要匹配 for,您必须使用 htmlFor.
IE7's attribute selector is buggy: as explained here, to match for you must use htmlFor.
所以,如果您需要 IE7 支持,请使用:
So, if you need IE7 support, use this:
.error[for="username"], .error[htmlFor="username"]
这篇关于CSS 选择器 - 如何在 CSS 中选择“for"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CSS 选择器 - 如何在 CSS 中选择“for"?
基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
