多选框选择背景色 [英] multi select box selected background color

查看:98
本文介绍了多选框选择背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

引用 帖子,

Referencing this post,


当前CSS不支持此功能。
您可以构建自己的插件或使用可通过DIV / CSS模仿此行为的插件。

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

但是您可以用Javascript实现它,您可以在 此处

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

这篇关于多选框选择背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆