日期:2014-05-16  浏览次数:20379 次

请教个JS关于setTimeout的问题
请教个JS关于setTimeout的问题
我想实现一个定时自动更新随机数字的一个JS脚本,不知道为什么总报错,以下是全部代码
<%randomize timer%>
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
</head> 
<script language="javascript"> 
setTimeout(txt,3000);
function txt(){ 
document.write ("<font color=red>OK<%=int(rnd*1000)+1%></font>")

</script>  
</html>
请熟悉JS的朋友告知原因和处理方法,谢谢!

------解决方案--------------------
HTML code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">   
function   txt(){   
document.body.innerHTML = "<font   color=red> OK " + parseInt(Math.random()*1000)+1 + "</font> ";
}
setInterval("txt()",1000); //用这个的话每间隔3000毫秒执行一次
//setTimeout(txt,3000);  //用这个的话执行一次就不执行了
</script> 
</head>
<body>
</body>
</html>