Loop through an Array of links and dynamically load the contents of each after a set interval

后端 未结 4 1330
孤城傲影
孤城傲影 2021-01-16 06:47

Using jQuery I would like to loop through an array of links and load the contents of each link into a DIV after a set interval. For example, if I have my parent page \"paren

4条回答
  •  逝去的感伤
    2021-01-16 07:26

    This will switch every 2 seconds (2000 milliseconds). Test online at http://jsbin.com/owoxo

    
    

    --

    var l = ["index.html","pictures.html","contact.html"], c = 0;
    setInterval(function(){
      $("#link a").attr("href",l[c]).html(l[c]);
      if (c++ > l.length) c = 0;
    }, 2000);
    

提交回复
热议问题