且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改多选下拉框中选定项目的背景颜色?

更新时间:2023-09-18 23:32:52

我们可以使用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/