我试图使用
JavaScript和/或jQuery将文本添加到div中,然后每隔10秒将文本更改为不同的文本 – 所以有点像纯文本的幻灯片.这是我的代码:
<div id="textslide"><p></p></div> <script> var quotes = new Array(); quotes[0] = "quote1"; quotes[1] = "quote2"; quotes[2] = "quote3"; quotes[3] = "quote4"; quotes[4] = "quote5"; var counter = 0; while (true) { if (counter > 4) counter = 0; document.getElementById('textslide').firstChild.innerHTML = quotes[counter]; counter++; setTimeout( // not sure what to put here,500); // Want to delay loop iteration } </script>
解决方法
HTML:
<div id="textslide"><p></p></div>
的JavaScript / jQuery的:
var quotes = [ "quote1","quote2","quote3","quote4","quote5",]; var i = 0; setInterval(function() { $("#textslide").html(quotes[i]); if (i == quotes.length) { i = 0; } else { i++; } },10 * 1000);