In actual needs, it may be necessary to stipulate that a function be executed after a specified time to achieve the desired purpose. This is also a timer effect. It happens that such a function setTimeout() has been given in js , let’s first introduce the sub-function
Usage:
Grammar:
This function can specify a specified code to be executed after the specified event. This code will only be executed once.
The setTimeout() function has two parameters. The first parameter specifies the execution code to be executed, and the second parameter specifies how long to execute the code, in milliseconds.
Code example:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.jb51.net/" /> <title>脚本之家</title> <style type="text/css"> div{ width:200px; height:50px; margin:0px auto; background-color:green; text-align:center; line-height:50px; color:red; } </style> <script type="text/javascript"> function tishi(){ alert("大家好欢迎来到脚本之家"); } setTimeout(tishi,5000) </script> </head> <body> <div>五秒弹出一个对话框</div> </body> </html>
The above code can specify that a dialog box will pop up after 5 seconds. The above uses the setTimeout() function to run the tishi() function after 5 seconds.
The above content is based on JavaScript to implement the relevant knowledge of executing a function after a certain period of time. Friends who are interested can learn together.