Home > Web Front-end > JS Tutorial > body text

The div automatically disappears after 2 seconds. js code sharing

小云云
Release: 2018-02-26 14:14:27
Original
2637 people have browsed it

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?

Syntax

setTimeout(code,millisec)

Tips and comments

setTimeout() only executes code once. If you want to call it multiple times, use setInterval() or have the code itself call setTimeout() again.

Example

<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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!