仅更改所选选项的颜色 [英] Change color of selected option only
本文介绍了仅更改所选选项的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个坐在表单元格中的选择器.表格行具有颜色,因此使用CSS我可以通过使用background-color:inherit;
将下拉菜单的背景更改为相同的颜色.但是,它将使用所有选项更改整个框的颜色.
I have a selector sitting in a table cell. The table row has a color, so using CSS I can change the drop-down's background to the same color by using background-color:inherit;
However, it changes the color of the entire box with all options.
是否可以仅通过jQuery来更改所选选项的颜色(如果没有CSS的话)?
Is it possible to change the color of the selected option only, if not with CSS perhaps with a help of jQuery?
推荐答案
使用jQuery一切皆有可能:) 您应该尝试这样做:
Everything is possible with jQuery :) You should try this:
$('.mySelect').change(function () {
$(this).find('option').css('background-color', 'transparent');
$(this).find('option:selected').css('background-color', 'red');
}).trigger('change');
这是一个实时演示
希望有帮助!
这篇关于仅更改所选选项的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文