Whether it is window. setTimeout or window. setInterval: parameters are not allowed when the function name is used as the call handle. The solution is to encapsulate the function based on the function, whether it is window. setTimeout or window. setInterval: parameters are not allowed 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.
First look at a simple code:
The Code is as follows:
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:
The Code is as follows:
Script language = "javascript">
Function show (name)
{Alert ("Hello World:" + name );}
Function _ show (name)
{
Return function ()
{
Show (name );
}
}
SetTimeout (_ show (name), 1000 );
Function
Script