繁体   English   中英

jQuery:使用setTimeout时函数未执行两次

[英]jQuery: function not excecuted twice when using setTimeout

我有以下代码,函数“ placeNewSponsor”应每4秒重复一次。 (该功能应放置图像,在3秒钟后隐藏它们,等待1秒钟并重复一次)。 但是,当我对此进行测试时,该功能仅执行一次。

 function placeNewSponsor() { $('.sponsorContainer').each(function() { var imageCount = $(".imageContainer").children().length; do { randomInt = Math.floor(Math.random() * imageCount + 1); } while ($.inArray(randomInt, usedNumbers) !== -1); usedNumbers.push(randomInt); var randomImage = $('.imageContainer a:nth-child(' + randomInt + ')').clone(); $(this).append(randomImage); }); usedNumbers = []; // Hide after 3 seconds setTimeout(function() { $('.sponsorContainer').hide(); }, 3000); // Re-activate function setTimeout(placeNewSponsor, 4000); } placeNewSponsor(); 

您隐藏了容器,但从未重现它们。

$('.sponsorContainer').show();  //show them
setTimeout(function(){ $('.sponsorContainer').hide(); }, 3000);  //hides them

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM