使用js定时跳转页面

来源:互联网 发布:淘宝卖家评价规则 编辑:程序博客网 时间:2024/05/21 09:32

html代码

<DOCTYPE HTML><html><head> <title>js进阶篇</title><script src="js/jstestTwo.js"></script></head><body><!--设置一个button , 点击后出现定时跳转--><input type="button" id="countdown" value="倒计时跳转" onclick="countDown()" /> </body></html>

jstestTwo.js

function countDownDate(){/*通过id获取html的button的value值*/    var butValue = document.getElementById("countdown").value;  /**如果值不为1(可能是非数字,可能是数字但是不等于1)**/    if((butValue*1) != 1){        /*如果是数字,则减一*/        if(!isNaN(butValue)){            /*这里要改变的是html里面的countdown值,所以使用getelementByID,如果使用butValue,则无法改变html里面的值,下同*/            document.getElementById("countdown").value = ((butValue*1)-1);         }else {        /*如果不是数字,给值赋值整数5*/            document.getElementById("countdown").value = 1*5;        }    }else{  /**如果值等于1,则赋值 跳转中 给值**/        document.getElementById("countdown").value = "跳转中";        /*同时跳转到百度首页*/        window.location.href = "http://www.baidu.com";    }}/*定时每1秒执行一次countDownDate()方法*/function countDown() {         setInterval(countDownDate,1000);}
0 0
原创粉丝点击