当我点击重置时,选择字段中的背景颜色不会变为白色。它显示最后选择的选项的颜色。请帮我解决这个问题。 我点击重置按钮时也想删除背景颜色。在此先感谢您的帮助..
<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>
答案 0 :(得分:0)
使用:
$('.resetButton').click(function()
{
$(this).closest('form').find('select').each(function()
{
$(this)[0].selectedIndex=0;
changecolor($(this).attr('id'),'white');
});
});
答案 1 :(得分:0)
您也可以使用.css('background',color)
来执行此操作