您的位置:首页 > Web前端 > JavaScript

利用javaScript实现页面倒计时跳转

2018-02-27 20:19 531 查看
用到的主要方法:
    1.setInterval(f, ms); 定时器

        参数列表:js函数、毫秒

    2.location.herf();跳转函数

        参数:需要跳转的URL
<!DOCTYPE html>
<html>
<head>
<title>JS实现定时跳转</title>
<script>
window.onload=function(){
var timeElement=document.getElementById("second");
var time=timeElement.innerHTML;
var times=setInterval(function() {
timeElement.innerHTML=time;
time--;
if(time==0){
clearInterval(times);
location.href="http://www.baidu.com";
}
}, 1000)
}
</script>
</head>

<body>
<h3>利用js实现倒计时跳转</h3><br>
开始计时<span id="second" style="color:red">5</span>s后跳转到百度首页,如果没有跳转点击<a href="www.baidu.com">这里</a>
</body>
</html>页面



哦了~

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  定时跳转