gpt4 book ai didi

javascript - 在选择中将第一个选项设为灰色,将其他选项设为黑色

转载 作者:行者123 更新时间:2023-11-28 02:21:00 26 4
gpt4 key购买 nike

<分区>

以下是我的代码,它在 Firefox 68.0.2 中运行良好,但在 Chrome 76 和 Safari 12.1.2 中运行良好。让我知道解决方法或我在这里做错了什么。

我想将第一个选择选项设置为灰色,将其余选项设置为黑色。

代码-

$(document).ready(function(){

$("select").change(function(){
if ($(this).val()=="") $(this).css({color: "#aaa"});
else $(this).css({color: "#000"});
});

});
select{
color:#aaa;
}
option:not(first-child) {
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select>
<option value="">Please select and option</option>
<option>#1</option>
<option>#2</option>
<option>#3</option>
<option>#4</option>
</select>

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com