Javascript 循环显示数字以出现在文档中
我试图每秒在屏幕上循环显示 10 个数字 (1 - 9)。有点像电影中的绿色矩阵代码..
这是我的代码,我一生都无法弄清楚我做错了什么,我尝试了很多其他事情,但这对我来说似乎是最正确的:
<html>
<head>
<script type="text/javascript">
function numberScroll(){
n = setInterval("Math.floor(Math.random()*11",100);
setInterval("document.getElementById('txt').innerHTML=n",100);
}
</script>
</head>
<body onLoad="numberScroll()">
<div id="txt"></div>
</body>
</html>
I'm trying to cycle through 10 numbers (1 - 9) on the screen every second. Sort of like the green matrix code from the movie..
here is my code, I cant for the life of me figure out what I'm doing wrong, I've tried many other things but this seems the most correct to me:
<html>
<head>
<script type="text/javascript">
function numberScroll(){
n = setInterval("Math.floor(Math.random()*11",100);
setInterval("document.getElementById('txt').innerHTML=n",100);
}
</script>
</head>
<body onLoad="numberScroll()">
<div id="txt"></div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该永远将字符串传递给setInterval/setTimeout。
使用函数代替:
http://jsfiddle.net/ThiefMaster/Tmqbk/
You should never pass a string to setInterval/setTimeout.
Use a function instead:
http://jsfiddle.net/ThiefMaster/Tmqbk/