javascript jquery延迟函数执行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17243271/
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
Jquery delay function execute
提问by user2501504
I want execute 2 functions in jquery but i need the second function execute after 3 seconds more or less , i try this , but if use this , the second function of jquery never execute finally , i put the script i create and i try works continue :
我想在 jquery 中执行 2 个函数,但我需要在或多或少 3 秒后执行第二个函数,我尝试了这个,但是如果使用这个,jquery 的第二个函数最终永远不会执行,我把我创建的脚本和我尝试继续工作:
jQuery("#tem_forma").hide();
delay(3000);
jQuery("#win").hide(1000);
How i can use delay function for wait 3 seconds for execute the next function , in this case the second
我如何使用延迟功能等待 3 秒来执行下一个功能,在这种情况下是第二个
Thank′s , Regards !!!
感谢和问候 !!!
回答by Sushanth --
Use setTimeout
使用setTimeout
jQuery("#tem_forma").hide();
setTimeout( function() { jQuery("#win").hide(1000); }, 3000);
This will make sure your functions gets executed after 3 seconds.
这将确保您的函数在 3 秒后执行。
回答by supersize
You can use .delay()
like this:
你可以这样使用.delay()
:
jQuery("#tem_forma").hide();
jQuery("#win").delay(3000).hide(1000);
But be aware that .hide()
needs to have (time) parameter to work in conjunction with .delay()
但请注意,.hide()
需要有(时间)参数才能与.delay()
回答by Brian Lewis
Is this what you meant?
这是你的意思吗?
jQuery("#tem_forma").hide();
jQuery("#win").delay(3000).hide(1000);