码迷,mamicode.com
首页 > 编程语言 > 详细

javascript 网页自动跳转

时间:2019-04-25 20:09:31      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:fun   set   add   javascrip   zh-cn   event   java   document   oca   

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button>点击跳转</button>
<div></div>
<script>
    var btn = document.querySelector(‘button‘);
    btn.addEventListener(‘click‘, function () {   // 注册按钮点击事件
        location.href = "http://www.baidu.com";  //  要跳转到的地址
    });
    var div = document.querySelector(‘div‘);
    var time = 5;   // 这里设置自动跳转的时间

    function f() {
        if (time > 0) {
            div.innerHTML = time + "s后跳转页面";
            time--;
        } else {
            location.href = ‘http://www.baidu.com‘;  // 要跳转到的地址
        }
    }

    setInterval(f, 1000);  // 计时器

</script>
</body>
</html>

 

javascript 网页自动跳转

标签:fun   set   add   javascrip   zh-cn   event   java   document   oca   

原文地址:https://www.cnblogs.com/nigori/p/10770569.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!