|
本文为大家介绍三种 js 刷新当前页面的方法: - reload() 方法;
- replace() 方法;
- 页面自动刷新;
方法1:reload() 方法reload()方法用于刷新当前文档。 reload() 方法类似于你浏览器上的刷新页面按钮。 location.reload(); 在按钮中可以使用 onclick 事件: <input type="button" onclick="javascript:location.reload();" value="刷新当前页面"> 点击下面按钮,刷新当前页面: 更多关于reload() 方法请参考文档:https://www.runoob.com/jsref/met-loc-reload.html 方法2:replace() 方法replace() 方法可用一个新文档取代当前文档。。 实例<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <script> function replaceDoc() { window.location.replace("https://www.runoob.com") } </script> </headgt; <body>
<input type="button" value="载入新文档替换当前页面" onclick="replaceDoc()">
</body> </html>
更多关于replace() 方法请参考文档:https://www.runoob.com/jsref/met-loc-replace.html
方法3:页面自动刷新页面自动刷新:把如下代码加入<head>区域中 <meta http-equiv="refresh" content="5"> 其中 5 指每隔 5 秒刷新一次页面。 尝试一下 » |