Javascript 如何删除带有重置按钮的选择选项标签中的背景色?

Javascript 如何删除带有重置按钮的选择选项标签中的背景色?,javascript,jquery,html,css,colors,Javascript,Jquery,Html,Css,Colors,单击“重置”时,选择字段中的背景色不会变为白色。它将显示最后选定选项的颜色。请帮我解决这个问题。 当我单击重置按钮时,我也想删除背景色。提前感谢你的帮助 <body> <form> <input type="reset" class="resetButton" /> <select id="select" style="color: white; width:60px;"onchange="changecolor(select,value)">

单击“重置”时,选择字段中的背景色不会变为白色。它将显示最后选定选项的颜色。请帮我解决这个问题。 当我单击重置按钮时,我也想删除背景色。提前感谢你的帮助

<body>
<form>

<input type="reset" class="resetButton" />
<select id="select" style="color: white; width:60px;"onchange="changecolor(select,value)">
<option value="white" style="background-color: white; "></option>
<option value="red" style="background-color: red; color: white;">AB</option>
<option value="blue" style="background-color: blue; color: white;">BC</option>
<option value="green" style="background-color: green; color: white;">CD</option>
<option value="orange" style="background-color: orange; color: white;">DE</option>
</select>

</form>
</body>


<script>
$(function()
{
    $('.resetButton').click(function()
    {
        $(this).closest('form').find('select').each(function()
        {
             $(this)[0].selectedIndex=0;


        });
    });
});
</script>

<script language="javascript" type="text/javascript">
function changecolor(id,color){
id.style.backgroundColor=color;
}
</script>

AB
卑诗省
光盘
判定元件
$(函数()
{
$('.resetButton')。单击(函数()
{
$(this).最近的('form').find('select').each(function())
{
$(此)[0]。已选择索引=0;
});
});
});
函数changecolor(id、颜色){
id.style.backgroundColor=颜色;
}
使用:


您也可以使用
.css('background',color)
来执行此操作


你好,米林,谢谢你的回答。它在我的页面上仍然不起作用。请在其他编辑器(如W3schools tryit编辑器)中尝试此代码,它仍然显示以前的背景色。您能给我一个带有“选择”和“单击”按钮的链接吗?您好,只需在W3schools编辑器中复制您和我的代码,并请检查它。它不会删除背景色。感谢AB BC CD DE anton将上面的链接提供给fiddle()。只需复制代码并在w3school编辑器中运行即可。
 $('.resetButton').click(function()
{
    $(this).closest('form').find('select').each(function()
    {
         $(this)[0].selectedIndex=0;
         changecolor($(this).attr('id'),'white');

    });
});