我需要 JavaScript 或 jQuery 来每隔几秒更改一次文本...无需用户做任何事情.
I need JavaScript or jQuery something to change text every few seconds... without the user doing anything.
例子:
欢迎"更改为Salmat datang";3 秒后变为Namaste"等并循环返回.
"Welcome" changes to "Salmat datang" changes to "Namaste", etc. after 3 seconds and loops back.
正如其他人所说,setInterval
是你的朋友:
As others have said, setInterval
is your friend:
var text = ["Welcome", "Hi", "Sup dude"];
var counter = 0;
var elem = document.getElementById("changeText");
var inst = setInterval(change, 1000);
function change() {
elem.innerHTML = text[counter];
counter++;
if (counter >= text.length) {
counter = 0;
// clearInterval(inst); // uncomment this if you want to stop refreshing after one cycle
}
}
<div id="changeText"></div>
这篇关于JavaScript/jQuery或每隔几秒钟更改一次文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!