JQuery 在文档准备好后等待 x 秒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5361852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:01:47  来源:igfitidea点击:

JQuery wait x seconds after document ready

jquery

提问by Email

following code waits till dom ready

以下代码等待 dom 准备就绪

jQuery(document).ready(function(){

what do i have to write to simple let the execution of the jquery function wait for 2 seconds after the document is ready?

我必须写什么来简单地让 jquery 函数的执行在文档准备好后等待 2 秒?

i need this to narrow down a conflict between multiple instances of a plugin.

我需要这个来缩小插件的多个实例之间的冲突。

THX

谢谢

回答by Alnitak

Wrap your existing function with a call to setTimeout, ie, replace your current:

调用 包装现有函数setTimeout,即替换当前函数:

jQuery(document).ready(function() {
     ....
});

with

jQuery(document).ready(function() {
    setTimeout(function() {
         ....
    }, 2000);
});

回答by Harsimer

You can use

您可以使用

$(window).load(function(){}); 

instead of

代替

$(document).ready(function(){});

I took reference from jquery forum

我参考了jquery 论坛

回答by Felix Kling

By using window.setTimeout.

通过使用window.setTimeout.

回答by Rael Max