Home >Web Front-end >JS Tutorial >Solution to jQuery setTimeout error when passing string parameters_jquery

Solution to jQuery setTimeout error when passing string parameters_jquery

WBOY
WBOYOriginal
2016-05-16 16:45:141318browse

When you plan to call some jQuery code to display a hidden element, and call setTimeout() to set its HTML content after a delay:

The code for the entire page is like this.

Copy code The code is as follows:






show next








I want to watch Check to see if there is indeed a problem with jQuery. I got the same error.

Later I read this book and found the problem.

setTimeout() accepts one character string parameter, it executes in the global scope, that is, it is outside any function. The simplest fix is ​​to use a local function (anonymous function) to solve this problem.
Copy code The code is as follows:






show next