我的网站上有一个部分,我想在上面显示一些警报或新闻。我想显示第一个新闻 x 秒,然后转到第二个新闻 x 秒,不再显示第一个新闻,然后到第三个,不显示第二个 .. 等等。我只是从 javascript 开始,然后我正在制作的代码只运行一次然后停止我希望这个继续无限或一个非常高的数字,以便人们可以在页面上看到新闻警报。一个接一个地。
我很感激我能得到的任何帮助。请给我看一个完整的代码,因为自从我大约 2 周前开始做这件事以来,我有点不适应。谢谢!
html:
<div id="news1">Here are some news! 1111</div>
<div id="news2">Here are some news! 2222</div>
<div id="news3">Here are some news! 3333</div>
CSS:
#news1, #news2, #news3{
visibility:hidden;
}
Javascript:
function showIt() {
document.getElementById("news1").style.visibility = "visible";
document.getElementById("news3").style.visibility = "hidden";
document.getElementById("news2").style.visibility = "hidden";
}
setInterval("showIt()", 3000);
function showIt2(){
document.getElementById("news2").style.visibility = "visible";
document.getElementById("news1").style.visibility = "hidden";
document.getElementById("news3").style.visibility = "hidden";
}
setInterval("showIt2()", 6000)
function showIt2(){
document.getElementById("news2").style.visibility = "visible";
document.getElementById("news1").style.visibility = "hidden";
document.getElementById("news3").style.visibility = "hidden";
setInterval("showIt3()", 3000);
}