Home > Web Front-end > Front-end Q&A > How to set jquery to stop for a few seconds

How to set jquery to stop for a few seconds

WBOY
Release: 2022-05-18 15:47:49
Original
2785 people have browsed it

In jquery, you can use the setTimeout() method to set a few seconds to stop before executing. This method is used to set a specified waiting time. When the time is up, a specified code will be executed. Syntax is "setTimeout(code to be executed, number of milliseconds to stop)".

How to set jquery to stop for a few seconds

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

How to set jquery to stop for a few seconds

setTimeout() is a method belonging to window. This method is used to call a function or calculate an expression after the specified number of milliseconds

Syntax The format can be the following two:

setTimeout(要执行的代码, 等待的毫秒数)
setTimeout(JavaScript 函数, 等待的毫秒数)
Copy after login

setTimeout() is to set a specified waiting time (unit is one thousandth of a second, millisecond). When the time is up, the browser will execute a specified code

Examples are as follows:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
setTimeout(function(){$("p").css("background-color","#66ccff");}, 3000 )
});
</script>
</head>
<body>
<h2>这是标题</h2>
<p style="background-color:#ff0000">这是一个段落。</p>
<p style="background-color:#00ff00">这是一个段落。</p>
<p style="background-color:#0000ff">这是一个段落。</p>
</body>
</html>
Copy after login

Output results:

How to set jquery to stop for a few seconds

Related video tutorial recommendations: jQuery video tutorial

The above is the detailed content of How to set jquery to stop for a 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