【发布时间】:2014-03-05 07:08:18
【问题描述】:
在这里我写了一个JavaScript 来在单击一次时将按钮的颜色更改为绿色,当我再次单击该按钮时,它的颜色应该变回橙色。按钮的默认颜色是橙色。我已经给出了rgb 的颜色值。但是,当我单击该按钮时,它的颜色从橙色变为绿色,当我再次单击它时,它的颜色保持绿色,不会变回橙色。请帮我解决这个问题。
<script>
function colorchange(id)
{
var background = document.getElementById(id).style.background;
if(background = "rgb(255,145,0)")
{
document.getElementById(id).style.background = "rgb(26,255,0)";
}
if(background == "rgb(26,255,0)")
{
document.getElementById(id).style.background = "rgb(255,145,0)";
}
}
</script>
这里是输入按钮的 HTML 代码
<input type="button" name="Ignore Select" value="Ignore Select" id="select" onclick="colorchange('select')" style="background:rgb(255,145,0);"/>
<input type="button" name="Ignore Delete" value="Ignore Delete" id="select1" onclick="colorchange('select1');" style="background:rgb(255,145,0);"/>
<input type="button" name="Ignore Insert" value="Ignore Insert" id="select2" onclick="colorchange('select2');" style="background:rgb(255,145,0);"/>
<input type="button" name="Ignore Update" value="Ignore Update" id="select3" onclick="colorchange('select3');" style="background:rgb(255,145,0);"/>
<input type="button" name="Ignore Sleep" value="Ignore Sleep" id="select4" onclick="colorchange('select4');" style="background:rgb(255,145,0);"/>
【问题讨论】:
-
试试这个代码jsfiddle.net/ku2Ye/2
标签: javascript jquery html