javascript 自动打字错误

来源:百度知道 编辑:UC知道 时间:2024/09/21 03:26:36
<script>

txt="helloworld"
line=""
i=0

function shows(){
if(i<txt.length){

line+=txt.charAt(i++)
document.write(line)
setTimeout(shows,1000)}
}
shows()

</script>

只能打出2个字来,我看我写的函数没有什么不对啊

不是没什么不对,而是完全不对。。。
<html>
<head>
<script language="javascript">
var txt="helloworld";
var line="";
var i=0;
function shows(){
if(i<txt.length){
line += txt.charAt(i++);
document.getElementById("aa").innerHTML=line;
setTimeout("shows()",1000);
}

}
window.onload=shows;
</script>
</head>
<body>
<span id="aa"></span>
</body>
</html>