Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript单击同一类中的多个链接,但在单击的每个不同链接之间存在延迟_Javascript_Jquery - Fatal编程技术网

使用Javascript单击同一类中的多个链接,但在单击的每个不同链接之间存在延迟

使用Javascript单击同一类中的多个链接,但在单击的每个不同链接之间存在延迟,javascript,jquery,Javascript,Jquery,类名是links,它下面有很多链接,如何为每个链接单击添加延迟,而不是让脚本一次又一次地单击同一链接 谢谢 $(function(){ window.location.href = $('.links').attr('href'); }); $(function () { // Grab all links into a wrapped set. var $links = $('.link'); // Start with the first link at index 0

类名是links,它下面有很多链接,如何为每个链接单击添加延迟,而不是让脚本一次又一次地单击同一链接

谢谢

$(function(){
    window.location.href = $('.links').attr('href');
});
$(function () {
  // Grab all links into a wrapped set.
  var $links = $('.link');
  // Start with the first link at index 0 in the wrapped set.
  var linkNum = 0;
  // Specify our delay time.
  var delay = 1; // seconds

  // Setup a click handler on all our links.
  $links.click(function (e) {
    var $this = $(this);
    console.log($this.text() + ' clicked.');
    $this.css({ color: '#f00' });

    // After our delay, click the next link.
    setTimeout(function () {
      ++linkNum;
      if (linkNum < $links.length) {
        $links.eq(linkNum).click();
      } else {
        linkNum = 0;
        console.log("All links clicked.");
      }
    }, delay * 1000);
  });

  $('button').click(function () {
    $links.eq(0).click();
  });
});