<!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>
代码写的很烂,各位看官指教!