测试的一点点后,在我看来,如果样式以任何方式修改IE不能打开下拉。
是的,好bug在那里。任何改变选择框(包括任何样式更改,甚至是通过更改父类名称触发的更改)都会使IE为其重新创建操作系统窗口小部件,这具有关闭它的副作用。所以下拉菜单打开,但在渲染前立即关闭。如果你在背景更改功能上设置了超时时间,你可以在后面看到它。
在聚焦之前,您需要的是第一个事件,因此您可以在打开之前更改样式,使下拉关闭。幸运的是,there is one!但它只是IE浏览器。对于其他浏览器(包括IE8),最好坚持简单的CSS :focus
选择:
<style>
select { background-color: #BDE5F8; }
select:focus, select.focus { background-color: white; }
</style>
<select>
<option>choose...</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<!--[if lt IE 8]><script>
// Fix lack of :focus selector for select elements in IE7-
//
var selects= document.getElementsByTagName('select');
for (var i= selects.length; i-- >0;) {
var select= selects[i];
select.onfocusin= function() {
this.className= 'focus';
};
select.onfocusout= function() {
this.className= '';
};
}
// Or, the same expressed in jQuery, since you mentioned using it
//
$('select').bind('focusin', function() {
$(this).addClass('focus');
}).bind('focusout', function() {
$(this).removeClass('focus');
});
</script><![endif]-->
。我甚至尝试更改父元素的className,以更改背景颜色,但获得相同的结果。 也许