==
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" />
< title > 无标题文档 </ title >
</ head >
< body >
< SCRIPT LANGUAGE ="JavaScript" >
<!-- Begin
var start = new Date();
start = Date.parse(start) / 1000 ;
var counts = 4 ;
function CountDown(){
var now = new Date();
now = Date.parse(now) / 1000 ;
var x = parseInt(counts - (now - start), 10 );
if (document.form1){document.form1.clock.value = x;}
if (x > 0 ){
timerID = setTimeout( " CountDown() " , 100 )
} else {
location.href = " http://www.ssbg.com.cn "
}
}
// End -->
</ script >
< SCRIPT LANGUAGE ="JavaScript" >
<!--
window.setTimeout( ' CountDown() ' , 100 );
-->
</ script >
< FORM NAME ="form1" >
< INPUT TYPE ="text" NAME ="clock" SIZE ="2" VALUE ="10" >
秒后自动跳转网页
</ FORM >
</ body >
</ html >
======================
<input type=button value="点击开始" onClick="t=5">
<span id="view"></span>
<script>
t = -1; // 计数器
setInterval("testTime()",1000); // 启动1秒定时
function testTime() {
if(t<0) return; // 计数器值小于0,表示尚未开始倒计时
if(t == 0) // 计数器值为0,转向
location = "http://www.sohu.com";
view.innerHTML = "<b>"+t+"</b>"; // 显示倒计时
t--; // 计数器递减
}
function offTime() {
if(event.srcElement.value != "点击开始") { // 若不是倒计时开始
t = -1; // 初始计数器
view.innerHTML = ""; // 清空倒计时
}
}
document.onclick = offTime; // 启动点击事件监视
</script>