第三次尝试。
我希望一组句子一个接一个地出现,并且相隔2秒。然后用一组新的句子重新开始,直到达到设定的结果。
我之前发布的代码太冗长了,最近的我可以得到我想要的结果,模仿我的错误代码,是这样的:
var counter;
var postHere;
var interval1;
var timeout1;
var timeout2;
var timeout3;
counter = 128;
postHere = document.getElementById("comment");
interval1 = setInterval(function() {
timeout1 = setTimeout(function() {postHere.innerHTML = "<p>First sentence = " + counter + "</p>";
timeout2 = setTimeout(function() {postHere.innerHTML = postHere.innerHTML + "<p>Second sentence = " + counter + "</p>";
timeout3 = setTimeout(function() {postHere.innerHTML = postHere.innerHTML + "<p>Third sentence = " + counter + "</p>";}, 2000);
}, 2000);
}, 2000);
counter = counter / 2;
if (counter < 1) {clearInterval(interval1);}
}, 2000);
&#13;
<div id="comment"></div>
&#13;
链接副本是我从中派生清除的地方,但这是该问题的扩展。