谁能告诉我问题出在哪里,我希望当我单击#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/