简体   繁体   English

如何使用重置按钮删除选择选项标签中的背景色?

[英]How to remove the background color in select option tag with reset button?

When I am clicking reset, the background color in select field is not changing to white. 当我单击“重置”时,“选择”字段中的背景色未更改为白色。 Its displaying the color of the last selected option. 它显示最后选择的选项的颜色。 Please help me out with this problem. 请帮我解决这个问题。 I want to remove the background color too when I am clicking reset button. 单击重置按钮时,我也想删除背景色。 Thanks in advance for your help.. 在此先感谢您的帮助..

<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>

use: 采用:

 $('.resetButton').click(function()
{
    $(this).closest('form').find('select').each(function()
    {
         $(this)[0].selectedIndex=0;
         changecolor($(this).attr('id'),'white');

    });
});

You can also use .css('background',color) to do this 您也可以使用.css('background',color)进行此操作

Check demo 检查演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据 OPTION 标签的背景在选择的 HTML 标签上设置背景颜色 - Set background color on select HTML tag based on the background of an OPTION tag 如何将 SELECT 的背景颜色从蓝色更改为灰色<OPTION>当鼠标悬停在选项上时专门标记? - How to change background color blue to grey for SELECT <OPTION> tag specifically when mouse hovers on options? 如何更改 hover 上 select 选项的背景颜色 - How to change the background color of a select option on hover 根据按钮重置选择选项 - Reset select option based on button 选择任何选项后如何更改选择菜单的背景颜色| 不是选项颜色 - How to change select menu background color after selected any option| not option color 根据按钮保留,隐藏和重置选择选项 - Remain, Hide and reset select option based on button jPicker重置按钮上的重置背景色以及如何一次打开单个jPicker对话框? - jPicker reset background color on reset button and how i get opened single jPicker dialog at a time? 如何在选择标签中选择选项 - How to select option in select tag 选择一个选项来更改页面的背景颜色 - Select an option to change a page's background color 如何将html中下拉菜单的默认高亮颜色从蓝色更改为其他颜色<select><option>标签 - How to change the default highlight color of drop down in html from blue to some other color for <select><option> tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM