各位老鸟,求帮助。一个很简单js,我想做一个按钮,它的背景颜色。点击奇数次为红色,偶数次为白色。
        <script type="text/javascript" >
        function change(btn) {
            var btn = document.getElementsByName("button");
            var times = 0;
            if (btn.onclicked) {
                times++;
                if (times % 2 == 0) {
                    btn.style.background = "red";
                }
                if (times % 2 == 1) {
                    btn.style.bac1ground = "white";
                }            }
        }
    </script>
</head>
<body>
<input type="button" value="点击试试" onclick="change(this)" />
</body>
</html>
这是我的代码,不知道哪里错了,还是怎么改。求帮助实现

解决方案 »

  1.   


    <!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>
        <title></title>
        <script type="text/javascript">
            var isJs = 1;
            function checkcolor(obj)
            {
                if (isJs%2==0)
                { 
                obj.style.background = "white";
                }
                else
                {
                    obj.style.background = "red";
                }
                isJs++;
             }
        </script>
    </head>
    <body>
    <input type="button" value="点击试试" onclick="checkcolor(this)" />
    </body>
    </html>