领先的免费Web技术教程,涵盖HTML到ASP.NET

网站首页 > 知识剖析 正文

如何刷新当前的页面

nixiaole 2025-01-01 22:14:36 知识剖析 17 ℃

本文为大家介绍三种 js 刷新当前页面的方法:

reload() 方法;

replace() 方法;

页面自动刷新;

方法1:reload() 方法

reload()方法用于刷新当前文档。

reload() 方法类似于你浏览器上的刷新页面按钮。

location.reload();

方法2:replace() 方法

replace() 方法可用一个新文档取代当前文档。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>replace() 方法</title>
<script>
function replaceDoc(){
window.location.replace("http://www.xxxxxx.com")
}
</script>
</head>
<body>
<input type="button" value="载入新文档替换当前页面" onclick="replaceDoc()">
</body>
</html>

方法3:页面自动刷新

页面自动刷新:把如下代码加入<head>区域中

<meta http-equiv="refresh" content="5">

其中5指每隔5秒刷新一次页面。

Tags:

最近发表
标签列表