In this article, we mainly share with you the js code for div to automatically disappear after 2 seconds. Using setTimeout(), the setTimeout() method is used to call functions or calculate expressions after the specified number of milliseconds. Hope it helps everyone.
There will be prompt information during the process of doing the four quadrants, but I want the prompt information to be automatically hidden after a certain period of time.
#As shown in the picture above, the prompt will automatically hide after 2 seconds. How to do this?
setTimeout(code,millisec)
setTimeout() only executes code once. If you want to call it multiple times, use setInterval() or have the code itself call setTimeout() again.
<html> <head> <script type="text/javascript"> function timedMsg() { var t=setTimeout("alert('5 seconds!')",5000) } </script> </head> <body> <form> <input type="button" value="Display timed alertbox!" onClick="timedMsg()"> </form> <p>Click on the button above. An alert box will be displayed after 5 seconds.</p> </body> </html>
Related recommendations:
JS/jQuery to implement DIV delay for a few seconds before disappearing or displaying
jQuery implements code sharing for swapping positions of buttons in two divs
jQuery clicks anywhere to hide the DIV function
The above is the detailed content of The div automatically disappears after 2 seconds. js code sharing. For more information, please follow other related articles on the PHP Chinese website!