JS中怎样用for循环做个文字倒计时出现的小程序、 就是隔几秒出现一个文字、
这是我写的代码、有问题的,帮忙修改下、谢谢!<title>无标题文档</title><scripttype="text/javascript">vararrs=["隔",...
这是我写的代码、有问题的 ,帮忙修改下、谢谢!
<title>无标题文档</title>
<script type="text/javascript">
var arrs=["隔","几","秒","出","现","一","个","文","字","、"]
var i=0;
function operA(){
var divObj=document.getElementById("divA");
for(i;i<arrs.length;i++){
divObj.innerHTML+=arrs[i];
//alert(arrs[i]);
continue;
}
setTimeout("operA()",5000);
}
</script>
</head>
<body>
<div id="divA"></div>
<form>
<input type="button" value="按钮" name="" onclick="operA()" />
</form>
</body> 展开
<title>无标题文档</title>
<script type="text/javascript">
var arrs=["隔","几","秒","出","现","一","个","文","字","、"]
var i=0;
function operA(){
var divObj=document.getElementById("divA");
for(i;i<arrs.length;i++){
divObj.innerHTML+=arrs[i];
//alert(arrs[i]);
continue;
}
setTimeout("operA()",5000);
}
</script>
</head>
<body>
<div id="divA"></div>
<form>
<input type="button" value="按钮" name="" onclick="operA()" />
</form>
</body> 展开
2个回答
展开全部
你应该使用 setInterval,而不是 setTimeout,for 用不上
<script type="text/javascript">
var arrs=["隔","几","秒","出","现","一","个","文","字","、"];
var i=0;
function operA() {
setInterval(function() {
if(i == arrs.length) {
i = 0;
}
document.getElementById("divA").innerHTML += arrs[i];
i++;
}, 50);
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询