gpt4 book ai didi

javascript - 选择的默认样式

转载 作者:行者123 更新时间:2023-11-30 09:03:33 25 4
gpt4 key购买 nike

<select id="select">
<option>1</option>
<option>2</option>
<option>3</option>
</select>

<span id="red">red </span> <span id="default">default</span>

$("#red").click(function(){
$("#select").css('background-color', 'red');
});

$("#default").click(function(){
$("#select").css('background-color', 'white');
});

如果我点击红色然后选择是红色的。我如何为选择设置默认样式,反对白色?

最佳答案

只需删除该属性即可将背景色重置为其默认值:

$("#default").click(function(){
$("#select").css('background-color', '');
});

有关引用,请参阅 jQuery .css() docs .引用:

Setting the value of a style property to an empty string — e.g. $('#mydiv').css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .css() method, or through direct DOM manipulation of the style property.

关于javascript - 选择的默认样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7077153/

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