文章目录

    • 1.添加meta标签
    • 2.添加script标签,写入刷新语句
    • 代码示例:

1.添加meta标签

<!-- 其中5是指每隔5s刷新一次页面 -->
<meta http-equiv="refresh" content="5">

用meta标签也跳转到指定页面

<meta http-equiv="refresh" content="10;url=http://www.51jfgou">

2.添加script标签,写入刷新语句

可以封装成函数

<script type="text/javascript">
	function myrefresh(){
		window.location.reload();
	}
	//指定1s刷新一次
	setTimeout('myrefresh()',1000);
</script> 

也可以直接用

<script type="text/javascript">
setTimeout(function(){
	window.location.reload()
},1000); //指定1秒刷新一次
</script>

代码示例:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- 其中5是指每隔5s刷新一次页面 
	<meta http-equiv="refresh" content="5">-->
	<title>刷新</title>
	<script type="text/javascript">
		function myrefresh(){
			window.location.reload();
		}
		//指定1s刷新一次
		setTimeout('myrefresh()',1000);
	</script> 
</head>
<body>
	<h1>大大大大 页面</h1>
</body>
</html>

更多推荐

HTML网页实现自动刷新