我想1秒改变一次文本的背景色,这样写怎么不对呢??
<script type="text/javascript">
var i=0;
function change()
{
 i++;
 if(i%2)
     {h3.background-color:blue}
else
      {h3.background-color:green}

aa=setTimeout("change()",1000)
</script>                                (这里定义一个函数让它每秒执行一次)
<body>
<h3>看这里</h3>
<input type="button" onclick="change()" value="点" />
</body>
(body里定义一个button,点击button开始执行change()函数)
可是为什么不行呢??求高手指导一下

解决方案 »

  1.   

    {h3.background-color:blue}h3.style.backgroundColor='blue';或者:
    h3.style.cssText ="background-color:blue";
      

  2.   

    h3又不是对象也不是变量怎么可能直接用呢?    var i=0;
        function change()
        {
            i++;
            var tab=document.getElementsByTagName("h3")[0];
            if(i%2)
                tab.style.backgroundColor="blue";
            else
                tab.style.backgroundColor="green";
            setTimeout("change()",1000);
        }