Home >Web Front-end >JS Tutorial >How does jquery trigger the effect every few seconds?

How does jquery trigger the effect every few seconds?

WBOY
WBOYOriginal
2021-12-13 11:15:372669browse

In jquery, you can use the "setTimeout()" method to achieve an interval of several seconds before triggering the effect. This method is used to call a function or calculate an expression after a specified number of milliseconds. The syntax is "setTimeout(requires execution Code, millisecond waiting time);".

How does jquery trigger the effect every few seconds?

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How jquery can trigger the effect every few seconds

In jquery, you can use setTimeout() to trigger the effect every few seconds. The setTimeout() method is used to call a function or calculated expression after a specified number of milliseconds.

The syntax is:

setTimeout(code, milliseconds, param1, param2, ...)
setTimeout(function, milliseconds, param1, param2, ...)

Among them:

How does jquery trigger the effect every few seconds?

The example is as follows:

<html>
<head>
<meta charset="utf-8">
<title>123</title>
</head>
<body>
<p>点击按钮,3 秒后会弹出 "Hello"。</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction() {
    setTimeout(function(){ alert("Hello"); }, 3000);
}
</script>
</body>
</html>

Output result:

How does jquery trigger the effect every few seconds?

After 3 seconds of clicking the button:

How does jquery trigger the effect every few seconds?

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How does jquery trigger the effect every few seconds?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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