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

How to refresh the page after two seconds in jquery

coldplay.xixi
coldplay.xixiOriginal
2020-12-01 15:39:374536browse

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!

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