如何使用 setTimeout 触发 jQuery 事件?

jqueryweb developmentfront end technology

jQuery setTimeout() 方法用于设置事件触发的间隔。

示例

在这里,我们将使用 jQuery 事件设置警告框的加载间隔为 3 秒:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#button1").click(function(){
       setTimeout("alert('Hello World!');", 3000);
    });
});
</script>
</head>
<body>

<button id="button1">Click</button>
<p>Click the above button and wait for 3 seconds. An alert box will generate after 3 seconds.</p>

<p></p>
</body>
</html>

相关文章