【发布时间】:2013-01-05 04:42:00
【问题描述】:
我想更改所选项目的背景颜色。 我的意思是蓝色:http://img844.imageshack.us/img844/3200/c0b8e4b9ceac4122bc5668a.png
【问题讨论】:
标签: html css drop-down-menu
我想更改所选项目的背景颜色。 我的意思是蓝色:http://img844.imageshack.us/img844/3200/c0b8e4b9ceac4122bc5668a.png
【问题讨论】:
标签: html css drop-down-menu
引用this帖子,
目前 CSS 不支持此功能。 您可以使用 DIV/CSS 构建自己的或使用模拟此行为的插件。
但是你可以通过 Javascript 来实现它,你可以看到 here
var sel = document.getElementById('select_id');
sel.addEventListener('click', function(el){
var options = this.children;
for(var i=0; i < this.childElementCount; i++){
options[i].style.color = 'white';
}
var selected = this.children[this.selectedIndex];
selected.style.color = 'red';
}, false);
【讨论】: