大家看看下面的JS代码有什么错误, 该怎么改????

来源:百度知道 编辑:UC知道 时间:2024/05/17 03:49:13
<html><head>
<style>body{text-align:center;}
.red{color:red;}
.yellow{color:yellow;}
.green{color:green}</style>
<script>
function char(){
other=c.className;
c.className=b.className;
b.className=a.className;
a.className=other;
setTimeout("char();",1000)
}
char()
</script></head>
<body>
<span class=red id=a>霓</span><span class=yellow id=b>虹</span><span class=red id=c>字</span>
</body>
</html>

script的位置放的不对,应该放在body里。
<html><head>
<style>body{text-align:center;}
.red{color:red;}
.yellow{color:yellow;}
.green{color:green}</style>
</head>
<body>
<span class=red id=a>霓</span><span class=yellow id=b>虹</span><span class=red id=c>字</span>
<script>
function char(){
with(document.all){
other=c.className;
c.className=b.className;
b.className=a.className;
a.className=other;
setTimeout("char();",1000)
}
}
char();
</script>
</body>
</html>