码迷,mamicode.com
首页 > Web开发 > 详细

js倒计时改进版

时间:2014-09-18 11:23:33      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:io   ar   div   sp   cti   代码   log   on   c   

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

<body>
<div><input id="time_h" type="text" value="" />点<input id="time_m" type="text" value=""/>分<input id="time_s" value="" type="text"/>秒<input onClick="djs()" type="button" value="开始"/></div>
<div id="time"></div>
<script>
var oTime=document.getElementById("time");

var sj=new Date;
var time_h,time_m,time_s;
document.getElementById("time_h").value=sj.getHours();
document.getElementById("time_m").value=sj.getMinutes();
document.getElementById("time_s").value=sj.getSeconds();
function time(){
var sj=new Date;
var gs=time_h*60*60+time_m*60+time_s;
var xs=sj.getHours()*60*60+sj.getMinutes()*60+sj.getSeconds();

var c=gs-xs;

if(c < 0){
alert(‘输入无效值,请重新输入‘);
clearInterval(t);
oTime.innerHTML="";
return;
}
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;
console.log(sj);
if(gs==xs){
clearInterval(t);
alert(‘时间到‘);
}


}

function djs(){
time_h=parseInt(document.getElementById("time_h").value);
time_m=parseInt(document.getElementById("time_m").value);
time_s=parseInt(document.getElementById("time_s").value);

t=setInterval(function(){time();},1000);
}</script>
</body>
</html>

 

代码写的很烂,各位看官指教!

js倒计时改进版

标签:io   ar   div   sp   cti   代码   log   on   c   

原文地址:http://www.cnblogs.com/xurui01/p/3978682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!