html倒计时 照着练习(抄袭)的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>倒计时</title> <link rel="stylesheet" type="text/css" href="倒计时.css" /> <script type="text/javascript"> function daojishi(){ var nowday=new Date();//现在 var endday;//截止日期 var endy=parseInt(document.getElementById("t1").value); var endmo=parseInt(document.getElementById("t2").value); var endd=parseInt(document.getElementById("t3").value); var endh=parseInt(document.getElementById("t4").value); var endm=parseInt(document.getElementById("t5").value); var ends=parseInt(document.getElementById("t6").value); //月份减1 endday=new Date(endy,endmo-1,endd,endh,endm,ends); //endday=new Date(2014,11,8,17,55,0); //总秒数ts //document.getElementById("main").innerHTML=endday-nowday; var ts=Math.round((endday-nowday)/1000); //总天数 var td=parseInt(ts/3600/24); //零几小时 var eh=parseInt((ts%(3600*24))/3600); //零几分钟 var em=parseInt((ts%3600)/60); //零几秒 var es=ts%60; document.getElementById("box").innerHTML="还剩"+td+"天"+eh+"时"+em+"分"+es+"秒"; if(ts<0){ alert("倒计时结束"); return; } window.setTimeout("daojishi()",1000); } </script> </head> <body> <h1 align="center">请输入截止日期的年月日,时分秒</h1> <div id="main"> <input type="text" id="t1"/>年 <input type="text" id="t2"/>月 <input type="text" id="t3"/>日 <input type="text" id="t4"/>时 <input type="text" id="t5"/>分 <input type="text" id="t6"/>秒 </div> <button id="b" onclick="daojishi()">开始倒计时</button> <div id="box"> </div> </body> </html>