SoFunction
Updated on 2025-04-07

JavaScript uses setTimeout to implement a delayed pop-up warning box

This article describes the method of using setTimeout to implement a delayed pop-up warning box. Share it for your reference. The details are as follows:

After the following code is executed, clicking the button will delay by 3 seconds. A warning box will pop up, which mainly demonstrates how to use setTimeout

<!DOCTYPE html>
<html>
<body>
<p>
Click the button to wait 3 seconds, then alert "Hello".
</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
setTimeout(function(){alert("Hello")},3000);
}
</script>
</body>
</html>

I hope this article will be helpful to everyone's JavaScript programming.