给你个思路:
1初始化时间,例如1小时5分钟30秒(也可以让用户手动设置,这里略)
保存在全局变量中
var hour,minute,second;
2设置定时每隔1秒执行function xxx
setInterval(function xxx(){...},1000);
3编写function用于每隔1秒更新时间,里面判断若倒计时为0时,隐藏div
function xxx(){
if(--second==0){
if(--minute==0){
if(--hour==0){
//隐藏div 设置style.display='none'
}
show(hour,minute,second);
second=60;
minute=60;
}
show(hour,minute,second);
second=60;
}
show(hour,minute,second);
}
function show(hour,minute,second){
var str_hour = hour<10?"0"+hour:""+hour;
var str_minute = minute<10?"0"+minute:""+minute;
var str_second = second<10?"0"+second:""+second;
//将这三个时分秒显示到div中指定位置
}