此代码似乎不起作用...它在很长一段时间后仅显示一次 twCharCount 元素。难道超时只能设置一个?有什么建议可以使这段代码更好吗? 感谢您的任何建议...
var timer = new Array();
var t=0;
var step=1000;
counter.hide();
var t =+ step;
timer[0] = setTimeout("$('#twCharCount').show()",t);
var t =+ step;
timer[1] = setTimeout("$('#twCharCount').hide()",t);
var t =+ step;
timer[2] = setTimeout("$('#twCharCount').show()",t);
var t =+ step;
timer[3] = setTimeout("$('#twCharCount').hide()",t);
var t =+ step;
timer[4] = setTimeout("$('#twCharCount').show()",t);
好的 .. 对不起......我在写这篇文章的时候有点不太清醒...... 当然,我一直在重新调用……这就是为什么所有同步执行的原因……
最佳答案
var intervalId = window.setInterval(function() {
$('#twCharCount').toggle();
}, 1000);
并停止闪烁 window.clearInterval(intervalId);
。
关于javascript - JavaScript 中只能有一个超时吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5584504/