【问题标题】:Jquery time between clicks点击之间的Jquery时间
【发布时间】:2023-03-27 03:41:01
【问题描述】:

谁能告诉我这里的问题出在哪里,我想当我点击#automatic 开始以 3 秒延迟打开新窗口时

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

【问题讨论】:

  • 我猜问题出在现代浏览器中内置的“弹出窗口拦截器”,以确保不可能出现这种烦人的废话,

标签: javascript jquery each settimeout


【解决方案1】:

如果您需要延迟 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 2017-05-19
    相关资源
    最近更新 更多