[英]Unobstrusive pseudo-classes and attribute selectors emulation in IE
I'm trying to emulate some pseudo-classes and attribute selectors in Internet Explorer 6 and 7, such as :focus
, :hover
or [type=text]
. 我正在尝试在Internet Explorer 6和7中模拟一些伪类和属性选择器,例如:focus
, :hover
或[type=text]
。 So far, I've managed to add a class name to the affected elements: 到目前为止,我已经设法将一个类名添加到受影响的元素中:
$("input, textarea, select")
.hover(function(){
$(this).addClass("hover");
}, function(){
$(this).removeClass("hover");
})
.focus(function(){
$(this).addClass("focus");
})
.blur(function(){
$(this).removeClass("focus");
});
$("input[type=text]").each(function(){
$(this).addClass("text");
});
However, I'm still forced to duplicate selector in my style sheets: 但是,我仍然被迫在样式表中重复选择器:
textarea:focus, textarea.focus{
}
And, to make things worse, IE6 seems to ignore all the selectors when it finds an attribute: 而且,更糟糕的是,IE6在找到属性时似乎会忽略所有选择器:
input[type=text], input.text{
/* IE6 ignores this */
}
And, of course, IE6 ignores selectors with multiple classes: 而且,当然,IE6会忽略具有多个类的选择器:
input.text.focus{
/* IE6 ignores this */
}
So I'm likely to end up with this mess: 因此,我很可能最终会陷入困境:
input[type=text]{
/* Rules here */
}
input.text{
/* Same rules again */
}
input[type=text]:focus{
}
input.text_and_focus{
}
input.text_and_hover{
}
input.text_and_focus_and_hover{
}
My question: is there any way to read the rules or computed style defined for a CSS selector and apply it to certain elements, so I only need to maintain one set of standard CSS? 我的问题:有什么方法可以读取为CSS选择器定义的规则或计算样式并将其应用于某些元素,因此我只需要维护一组标准CSS?
If you're already depending on javascript with your styles (otherwise, neither :focus
or .focus
work in IE6), I advice you to use IE7.js
by Dean Edwards, which js-enhance ie6. 如果您已经在样式上使用javascript(否则, :focus
或.focus
在IE6中.focus
不起作用),我建议您使用Dean Edwards的IE7.js
,它可以增强IE6的效果。
http://code.google.com/p/ie7-js/ http://code.google.com/p/ie7-js/
I found this lovely piece of software: 我发现了这个可爱的软件:
It basically covers my requirements (unobtrusive code that doesn't require specific CSS rules), although it doesn't emulate input[type=text]
. 尽管它不模拟input[type=text]
,但它基本上满足了我的要求(不需要特定CSS规则的非干扰性代码)。
If you know about something else on this line, feel free to add a new answer. 如果您知道此行的其他信息,请随时添加新答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.