js倒计时

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<div id="time"></div>
<script>
var oTime=document.getElementById("time");
var sj=new Date;
//alert(sj.getHours());
//alert(sj.getMinutes());
//alert(sj.getSeconds());


function time(h,m,s){
var sj=new Date;
console.log(sj);
var gs=h*60*60+m*60+s;
var xs=sj.getHours()*60*60+sj.getMinutes()*60+sj.getSeconds();
var h_xiao=parseInt((gs-xs)/3600);
var m_xiao=parseInt(((gs-xs)/60)%60);
var s_xiao=(gs-xs)%60;
oTime.innerHTML=h_xiao+":"+m_xiao+":"+s_xiao;

if(gs==xs){

clearInterval(t);
alert('时间到');
}
}
var t=setInterval(function(){time(23,12,30);},1000);
</script>
</body>
</html>

posted @ 2014-09-17 22:51  随波逐流196  阅读(93)  评论(0编辑  收藏  举报