【发布时间】:2010-05-04 09:53:10
【问题描述】:
我正在尝试在 Internet Explorer 6 和 7 中模拟一些伪类和属性选择器,例如 :focus、:hover 或 [type=text]。到目前为止,我已经设法为受影响的元素添加了一个类名:
$("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");
});
但是,我仍然不得不在样式表中复制选择器:
textarea:focus, textarea.focus{
}
而且,更糟糕的是,IE6 在找到属性时似乎会忽略所有选择器:
input[type=text], input.text{
/* IE6 ignores this */
}
当然,IE6 会忽略具有多个类的选择器:
input.text.focus{
/* IE6 ignores this */
}
所以我很可能会陷入这种混乱:
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{
}
我的问题:有没有办法读取为 CSS 选择器定义的规则或计算样式并将其应用于某些元素,所以我只需要维护一组标准 CSS?
【问题讨论】:
标签: javascript jquery css internet-explorer