【发布时间】:2022-01-24 20:49:09
【问题描述】:
我有一个部分,该部分有 3 个标题,我想一一展示 间隔 10 秒
就像在strat你会有一个标题和它的内容,然后10秒后标题内的文本会改变,10秒后它会改变aagin
<h2>helllo world</h2>
<h2>helllo world 2</h2>
<h2>helllo world 3</h2>
我有 3 个标题,必须一一显示,
在我的代码中,我确实喜欢这个禁用所有然后显示一个但我有问题循环它
<body>
<h1>hellow orld</h1>
<h1>hellow orld2</h1>
<h1>hellow orld3</h1>
<script>
let myarr = document.querySelectorAll('h1');
let myindex = 0;
console.log(myarr)
for (let index2 = 0; index2 < 10000; index2++) {
one();
setTimeout(impFunct, 1000);
}
function one() {
myarr.forEach(element => {
element.style.display = 'none';
});
myarr[myindex].style.display = 'block';
}
function impFunct() {
if(myindex==2) {myindex=0; return;}
myindex++
console.log(myindex);
}
</script>
</body>
如果你知道任何插件或任何方法可以做到这一点,我所做的一切都是为了在 wordpress 中工作。
请帮忙
【问题讨论】:
标签: javascript html wordpress