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

How does jquery trigger the effect every few seconds?

WBOY
Release: 2021-12-13 11:15:37
Original
2642 people have browsed it

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, ...)
Copy after login

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

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!

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!