Home > Web Front-end > JS Tutorial > How to refresh the page after two seconds in jquery

How to refresh the page after two seconds in jquery

coldplay.xixi
Release: 2020-12-01 15:39:37
Original
4624 people have browsed it

How to refresh the page after two seconds in jquery: First, use [$(function(){})] to execute the method body in the function when the page is loaded; then use [setTimeout()] Just execute [location.reload()] regularly to achieve refresh.

How to refresh the page after two seconds in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

How to refresh the page after two seconds in jquery:

1. Create a new html file, named test.html, to explain how to implement two seconds in jquery Refresh the page after seconds.

How to refresh the page after two seconds in jquery

2. In the test.html file, introduce the jquery.min.js library file and successfully load the file before you can use the methods in jquery.

How to refresh the page after two seconds in jquery

##3. In the test.html file, write the

<script></script> tag. The js logic code of the page will be written in within this tag.

How to refresh the page after two seconds in jquery

4. In order to show the effect, new Date() is used here to obtain the current system time, and

write() is used to output the time on the page. .

How to refresh the page after two seconds in jquery

5. In the test.html file, use

$(function(){ }) to execute the functions in the function when the page is loaded. The method body is mainly used to re-time after each refresh of the page.

How to refresh the page after two seconds in jquery

6. In the function() method body, use

setTimeout() to perform operations regularly, for example, perform location every 2 seconds .reload() method to refresh the page.

How to refresh the page after two seconds in jquery

#7. Open the test.html file in the browser to check the effect.

How to refresh the page after two seconds in jquery

Related free learning recommendations:

javascript (video)

The above is the detailed content of How to refresh the page after two seconds in jquery. 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