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

使用JavaScript刷新网页的方法_基础知识

WBOY
Release: 2016-05-16 15:56:39
Original
1481 people have browsed it

 可以使用JavaScript location.reload方法刷新网页。当用户点击一个链接此代码可以自动在一个事件调用。

如果想使用鼠标点击刷新网页,可以用下面的代码:

<a href="javascript:location.reload(true)">Refresh Page</a>

Copy after login

要了解它更好的办法,可以刷新页面
自动刷新:

还可以使用JavaScript后自动给定时间段,以刷新页面。以下是每5秒后会刷新此页面的例子。可以改变这个时候按您的要求。

<html>
<head>
<script type="text/JavaScript">
<!--
function AutoRefresh( t ) {
 setTimeout("location.reload(true);", t);
}
//  -->
</script>
</head>
<body onload="JavaScript:AutoRefresh(5000);">
<p>This page will refresh every 5 seconds.</p>
</body>
</html>

Copy after login

这里的 setTimeout()是一个内置的JavaScript函数,可用于给定的时间间隔之后执行另一个函数。

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!