[英]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)
进行此操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.