js编写倒计时跳转页面

来源:互联网 发布:it服务管理体系认证 编辑:程序博客网 时间:2024/03/29 23:21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script>
window.onload=function(){
var op=document.getElementsByTagName("p")[0];
var ospan=document.getElementsByTagName("span")[0];
var oa=document.getElementsByTagName("a")[0];
var num=0;
function djs(){
        num=parseInt(ospan.innerHTML);
        --num;
        ospan.innerHTML=num;

        if(num==0){

           window.location.replace(oa.href);

           clearInterval(x)

         }

}
var x=setInterval(djs,1000)
}
</script>
    <title>倒计时</title>
  </head>
<body>
<p>将在<span>5</span>秒之后回到商城</p>
    <a href="http://www.baidu.com">返回百度</a>
  </body>
</html>
0 0