javascript - Jquery 两次点击之间的时间

标签 javascript jquery each settimeout

谁能告诉我问题出在哪里,我希望当我单击#automatic 时延迟 3 秒开始打开新窗口

$('#automatic').click(function(){           
     $('.autosend').each(function() {
    //window.open( $(this).attr('href') );
    var openwindow = window.open( $(this).attr('href') );
    setTimeout(openwindow,3000);
    });         
            });

最佳答案

如果您需要延迟 3 秒打开新窗口,则此行是错误的:

setTimeout(openwindow,3000);

$(function () {
  $('#automatic').click(function(){
    $('.autosend').each(function(index, element) {
      $('#txt').text($('#txt').text() + '\n' + (index * 3000));
      setTimeout(function() {
        var openwindow = window.open( $(this).attr('href') );
        $('#txt').text($('#txt').text() + '\n' + 'Window open: ' + $(this).attr('href'));
      }.bind(this), index * 3000);
    });
  });
});
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<button id="automatic">Automatic</button>
<a href="1.html" class="autosend"></a>
<a href="2.html" class="autosend"></a>
<a href="3.html" class="autosend"></a>
<a href="4.html" class="autosend"></a>
<textarea id="txt" style="height: 200px"></textarea>

关于javascript - Jquery 两次点击之间的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38815879/

相关文章:

javascript - 动态多级each() jQuery

javascript - 单击时不更新函数的输出

javascript - 尝试声明接口(interface)时出现 Google Chrome WebUSB API 错误

php - 下拉设置 session 变量

javascript - Firebase 身份验证跟踪表?

loops - Grails-仅在g:each中的前十个值

javascript - 谷歌地图显示 :None Problem

jquery - 图像转换示例 : How to do them in Jquery

jquery - 设置内容可编辑元素的最大长度