CSS选择器 - 如何在CSS中选择“for”? [英] CSS selectors - how to select 'for' in CSS?
问题描述
我正在使用jQuery验证。
当for现在有效时,验证器会创建:
< label class =errorfor =usernamegenerated =true>
由于所有标签都有相同的 class = error CSS这确切一个基于'?
我知道如何使用jQuery排序,但总是寻找最干净, 。
使用(CSS2)属性选择器:
.error [for =username]
所有现代浏览器。
IE7的属性选择器错误:如下所述,要匹配为您必须使用
htmlFor
。
因此,如果您需要IE7支持,请使用:
.error [for =username],.error [htmlFor =username]
>感谢IE7,让我的答案是它需要的时间的两倍。
I'm using jQuery validation.
When for is now valid, validator is creating those:
<label class="error" for="username" generated="true">
As all label has got the same class=error can I select with CSS this exact one based on 'for'?
I know how to sort this out with jQuery - but always looking for cleanest, purest way. Any suggestion much appreciated.
Pete
Using the (CSS2) attribute selector:
.error[for="username"]
This will work in IE8+ and all modern browsers.
IE7's attribute selector is buggy: as explained here, to match for
you must use htmlFor
.
So, if you need IE7 support, use this:
.error[for="username"], .error[htmlFor="username"]
Thanks IE7, for making my answer over twice as long as it needed to be.
这篇关于CSS选择器 - 如何在CSS中选择“for”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!