我试图将第一个选项的颜色更改为灰色,只有文本(选择一个选项),但在这里它不起作用:
.grey_color {
color: #ccc;
font-size: 14px;
}
<select id="select">
<option selected="selected"><span class="grey_color">select one option</span></option>
<option>one</option>
<option>two</option>
<option>three</option>
<option>four</option>
<option >five</option>
</select>
我的jsfiddle在这里jsfiddle
Suresh,您不需要在代码中使用任何内容。
你需要的只是这样的:
.others {
color:black
}
<select id="select">
<option style="color:gray" value="null">select one option</option>
<option value="1" class="others">one</option>
<option value="2" class="others">two</option>
</select>
但正如您所看到的,因为选项中的第一个项目是选择控件显示的第一个项目,所以您看不到其指定的颜色。如果您打开选择列表并查看打开的项目,您将看到可以为第一个选项指定灰色。
所以你需要 jQuery 中的其他东西。
$(document).ready(function() {
$('#select').css('color','gray');
$('#select').change(function() {
var current = $('#select').val();
if (current != 'null') {
$('#select').css('color','black');
} else {
$('#select').css('color','gray');
}
});
});
这是我的代码jsFiddle.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)