Parameter passing in SetTimeOut in JQuery

Source: Internet
Author: User
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... SyntaxHighlighter.

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.