JS定时跳转URL并输出剩余秒数

时间:2021-08-18 01:15:00

1. [代码][JavaScript]代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script language='javascript' type='text/javascript'>
var secs =0; //倒计时的秒数
var URL ;
function Load(url){
    URL =url;
    for(var i=secs;i>=0;i--)
    {
        window.setTimeout('doUpdate(' + i + ')', (secs-i) * 1000);
    }
}
 
function doUpdate(num)
{
    document.getElementById('ShowDiv').innerHTML = num;
    if(num == 0) { window.location=URL; }
}
</script>
</head>
 
<body>
 
<div id="ShowDiv"></div>
 
<script language="javascript">  
    Load("http://www.52lmy.com");
</script>