JavaScript's time out function is:
setTimeout(fun, 3600);
but what if I don't want to run any other fun开发者_StackOverflow中文版ction. Can I do setTimeout(3600);
?
Based on what you are saying you are simply trying to delay execution within a function.
Say for example you want to run an alert, and after 2 more seconds a second alert like so:
alert("Hello")
sleep
alert("World")
In javascript, the only 100% compatible way to accomplish this is to split the function.
function a()
{
alert("Hello")
setTimeout("b()",3000);
}
function b()
{
alert("World");
}
You can also declare the function within the setTimeout itself like so
function a()
{
alert("Hello");
setTimeout(function() {
alert("World");
},3000);
}
I'm not sure what you are trying to do. If you want nothing to happen after the period of time, why do you need a setTimeout()
in the first place?
You could always pass a handler which does nothing:
setTimeout(function() { }, 3600);
But I can hardly imagine any scenario in which this would be useful.
精彩评论