Home >Web Front-end >JS Tutorial >How does jquery trigger the effect every few seconds?
In jquery, you can use the "setTimeout()" method to achieve an interval of several seconds before triggering the effect. This method is used to call a function or calculate an expression after a specified number of milliseconds. The syntax is "setTimeout(requires execution Code, millisecond waiting time);".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How jquery can trigger the effect every few seconds
In jquery, you can use setTimeout() to trigger the effect every few seconds. The setTimeout() method is used to call a function or calculated expression after a specified number of milliseconds.
The syntax is:
setTimeout(code, milliseconds, param1, param2, ...) setTimeout(function, milliseconds, param1, param2, ...)
Among them:
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <p>点击按钮,3 秒后会弹出 "Hello"。</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { setTimeout(function(){ alert("Hello"); }, 3000); } </script> </body> </html>
Output result:
After 3 seconds of clicking the button:
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of How does jquery trigger the effect every few seconds?. For more information, please follow other related articles on the PHP Chinese website!