Javascript 5秒后执行javascript函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29675539/
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-23 03:46:09 来源:igfitidea点击:
execute javascript function after 5 seconds
提问by Jonathan Etienne
I have this function, which I would like to be executed after 5 seconds:
我有这个功能,我想在 5 秒后执行:
$(document).ready(function() {
$("#signInButton").trigger('click');
});
Thank you
谢谢
回答by kapantzak
Use setTimeout()function:
使用setTimeout()功能:
$(document).ready(function() {
setTimeout(function() {
$("#signInButton").trigger('click');
}, 5000);
});
回答by prog1011
Use setTimeout()
$(document).ready(function() {
setTimeout(function() {
$("#signInButton").trigger('click');
}, 5000); // for 5 second delay
});
回答by graycodes
$(document).ready(function() {
setTimeout(function() {
$("#signInButton").trigger('click');
}, 5000);
});
回答by Mox Shah
Something like this ?
像这样的东西?
$(document).ready(function() {
setTimeout(function() {
$("#signInButton").trigger('click');
}, 5000);
$("#signInButton").click(function(){
alert("I'm clicked!");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="signInButton" value="Click Me" />
Learn more about window's setTimeOutmethod
了解有关 window 的setTimeOut方法的更多信息

