【问题标题】:workaround for input[type="text"]:focus in IE6input[type="text"]:focus 在 IE6 中的解决方法
【发布时间】:2011-09-20 13:09:12
【问题描述】:
input[type="text"]:focus{
border:solid 2px red;
}
如果我使用上面的 CSS 规则,它在 IE6 中不起作用,它只是禁用了文本控件。我知道 CSS 位可以使用条件注释来处理。现在我明白了在 IE6 中更改边框我必须使用 javascript 或 jQuery。我的问题是,仅当浏览器是 IE6 时,是否存在类似于 CSS 的 java 脚本的条件注释,该脚本将更改边框的函数绑定到控件?因为现代浏览器将不需要此代码。希望我能说得通。
【问题讨论】:
标签:
javascript
css
internet-explorer-6
【解决方案1】:
做同样的事情:
<!--[if lte IE 6]>
<script type='text/javascript'>
// IE JAVASCRIPT HERE
</script>
<![endif]-->
【解决方案4】:
没有选择器可以为 IE6 做到这一点,如果您绝对必须支持此功能,您将不得不使用 javascript 的帮助。将此功能放在您的页面上:
function appendInputTypeClasses() {
if (!document.getElementsByTagName )
return;
var inputs = document.getElementsByTagName('input');
var inputLen = inputs.length;
for ( i=0;i<inputLen;i++ ) {
if ( inputs[i].getAttribute('type') )
inputs[i].className += ' '+inputs[i].getAttribute('type');
}
}
这会将输入的类型添加到类中,因此您可以使用:
input[type='text'],input.text
input[type='radio'],input.radio
input[type='checkbox'],input.checkbox