multi select box selected background color | css

2019-08-27 11:08发布

I would like to change the color of selected item's background. I mean that blue color : http://img844.imageshack.us/img844/3200/c0b8e4b9ceac4122bc5668a.png

1条回答
走好不送
2楼-- · 2019-08-27 11:38

Referencing this post,

Currently CSS does not support this feature. You can build your own or use a plug-in that emulates this behaviour using DIVs/CSS.

However you can achieve it doing Javascript which you can see 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);
查看更多
登录 后发表回答