Whether it is window. setTimeout or window. setInterval, parameters cannot be included when the function name is used as the call handle. If you want to pass in parameters, custom parameters, or event parameters, the solution is to encapsulate them on the basis of this function. The specific principle is unclear, but the following solution can solve this problem.
Let's look at a simple code:
Function show (){
Alert ("Hello World ");
}
SetTimeout (show, 1000 );
The effect of this Code is to display hello world in 1 second, but if it is changed
SetTimeOut (show (), 1000 );
It will be immediately displayed, and the delay effect cannot be reached. However, you can add quotation marks. For example:
SetTimeOut ("show ()", 1000 );
You can. However, if a parameter is included, it still does not work, for example:
SetTimeOut ("Display (name)", 1000)
In this case, a comparison method is used to write another function, which returns a function without parameters, as shown below:
<Script language = "javascript">
Function show (name)
{Alert ("Hello World:" + name );}
Function _ show (name)
{
Return function ()
{
Show (name );
}
}
SetTimeout (_ show (name), 1000 );
Function
</Script>