<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test</title> <script src="/jquery-3.4.1.min.js"></script> <script> var b = new Array(5000, 6000, 4000); $(function () { setSelectedItem(0); var selectedIndex; var playID; function setSelectedItem(index) { selectedIndex = index; clearInterval(playID); //自动播放 playID = setInterval(function () { var index = selectedIndex + 1; if (index > b.length - 1) index = 0; alert(b[index]); setSelectedItem(index); }, b[index]); } }) </script> </head> <body> </body> </html>
上面代码5秒后弹出5000,6秒后弹出6000,4秒后弹出4000依次循环弹出。
后续会陆续更新其他资料,喜欢请关注哦!