1- 执行一次(延时定时器)
var t1 = window.setTimeout(function() {
console.log(‘1秒钟之后执行了‘)
},1000)
window.clearTimeout(t1) // 去除定时器
2- 重复执行(间歇定时器)
var t2 = window.setInterval(function() {
console.log(‘每隔1秒钟执行一次‘)
},1000)
window.clearInterval(t2) // 去除定时器
本文为大家介绍三种 js 刷新当前页面的方法:
reload()方法用于刷新当前文档。
reload() 方法类似于你浏览器上的刷新页面按钮。
location.reload();
replace() 方法可用一个新文档取代当前文档。。
<!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鸟教程(runoob.com)</title><script>function replaceDoc(){ window.location.replace("http://www.runoob.com")}</script></head><body><input type="button" value="载入新文档替换当前页面" onclick="replaceDoc()"></body></html>
页面自动刷新:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="5">
其中5指每隔5秒刷新一次页面。