<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自动跳转首页</title>
<style>
p{
text-align : center;
}
span{
color:red;
}
</style>
</head>
<body>
<p>
<span id="time">5</span>秒之后,自动跳转首页...
</p>
<script>
//获取倒计时秒数
var time = document.getElementById("time");
var second = 5;
function showTime(){
second -- ;
if(second <= 0){
//时间到了,跳转首页
location.href = "https://www.baidu.com";
}
time.innerHTML = second;
}
setInterval(showTime,1000);
</script>
</body>
</html>
js小案例:使用location.href自动跳转页面
原创a772304419 ©著作权
©著作权归作者所有:来自51CTO博客作者a772304419的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
location.href
location.href location.href="http://www.baidu.com"
html HTML javascript