In jquery, you can use the setTimeout() method to set a few seconds to stop before executing. This method is used to set a specified waiting time. When the time is up, a specified code will be executed. Syntax is "setTimeout(code to be executed, number of milliseconds to stop)".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
setTimeout() is a method belonging to window. This method is used to call a function or calculate an expression after the specified number of milliseconds
Syntax The format can be the following two:
setTimeout(要执行的代码, 等待的毫秒数) setTimeout(JavaScript 函数, 等待的毫秒数)
setTimeout() is to set a specified waiting time (unit is one thousandth of a second, millisecond). When the time is up, the browser will execute a specified code
Examples are as follows:
<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js"></script> <script> $(document).ready(function(){ setTimeout(function(){$("p").css("background-color","#66ccff");}, 3000 ) }); </script> </head> <body> <h2>这是标题</h2> <p style="background-color:#ff0000">这是一个段落。</p> <p style="background-color:#00ff00">这是一个段落。</p> <p style="background-color:#0000ff">这是一个段落。</p> </body> </html>
Output results:
Related video tutorial recommendations: jQuery video tutorial
The above is the detailed content of How to set jquery to stop for a few seconds. For more information, please follow other related articles on the PHP Chinese website!