【问题标题】:multi select box selected background color [duplicate]多选框选择的背景颜色[重复]
【发布时间】:2013-01-05 04:42:00
【问题描述】:

我想更改所选项目的背景颜色。 我的意思是蓝色:http://img844.imageshack.us/img844/3200/c0b8e4b9ceac4122bc5668a.png

【问题讨论】:

标签: html css drop-down-menu


【解决方案1】:

引用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);

【讨论】:

  • 我无法更改多选中选定选项的颜色,也无法更改其背景颜色(至少在 chrome 上)
猜你喜欢
  • 2018-10-28
  • 2012-10-01
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
  • 2013-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多