比如有三种颜色。点一次变一种。点倒第4次时返回默认色。要的是按钮背景变色

解决方案 »

  1.   

    http://tstring.com.cn/loopbackcolor.aspx
    ie8,chrome下都没问题了,firefox下有问题,但是一时着急,搞不来,有空我再研究研究,参考下吧,问题范围已经缩小不不了
      

  2.   

    给个例子给你<script>
    function aa()
    {
    document.getElementById("a").style.backgroundColor="#FF0000"}
    </script>
    <span id="a" style="height:20px;width:100px;background-color:#999;" onclick="javascript:aa();">test1</span>
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Change btn Color</title>
    <script language="javascript">
    var colors=new Array();
    colors[0]="";
    colors[1]="#220099";
    colors[2]="#ff2233";
    colors[3]="#114455";
    window.onload=function(){
    var btn_change=document.getElementById('change');
    var currIndex=0;
    //btn_change.style.backgroundColor=colors[currIndex];
    btn_change.onclick=function(){
    currIndex=(currIndex+1)%4;
    //alert(currIndex);
    btn_change.style.backgroundColor=colors[currIndex];
    }
    }
    </script>
    </head><body>
    <input type="button" value="ChangeColor" id="change">
    </body>
    </html>IE6 FF 下测试过,没问题!其他浏览器没有!