如何更改多选下拉框中选定项目的背景颜色? [英] how to change background color of selected items in multiselect dropdown box?

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

问题描述

我想在多选下拉框中为选定的项目给出黄色。默认情况下,它选择后有灰色背景,
我想在 HTML,CSS 中执行此操作。



解决方案

我们可以使用JS来选择DOM。

  $('select')。change(function(){
$('option')。css('background','none') ;
$('option:selected')css('backgroundColor','red');
})change()

< select&
< option> 1111111< / option>
< option> 222222222< / option>
< option> 33333333< / option>
< option> 44444444< / option>
< / select>

演示: http://jsfiddle.net/TxbVt/1/


I want to give the yellow color to the selected items in multiselect dropdown box. By default it has gray background after selecting, I want to do this in HTML, CSS.

Can any one help in this?

解决方案

We can use JS to select the DOMs.

$('select').change(function() {
    $('option').css('background', 'none');
    $('option:selected').css('backgroundColor', 'red');
}).change()

<select>
    <option>1111111</option>
    <option>222222222</option>
    <option>33333333</option>
    <option>44444444</option>
</select>

Demo : http://jsfiddle.net/TxbVt/1/

这篇关于如何更改多选下拉框中选定项目的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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