JS实现计时器,很不错的效果哦
<script language="javascript">
var se,m=0,h=0,s=0,ss=1,istrue=true;
function second(){
if((ss%100)==0){s+=1;ss=1;}
if(s>0 && (s%60)==0){m+=1;s=0;}
if(m>0 && (m%60)==0){h+=1;m=0;}
var sstext = ss < 10 ? "0"+ss : ss;
t=h+"时"+m+"分"+s+"秒"+sstext+"毫秒";
document.getElementById("showtime").innerHTML=t;
ss+=1;
}
function startclock(){if(se==null||se=='undefined'||istrue)se=setInterval("second()",1);istrue=false;}
function pauseclock(){clearInterval(se);istrue=true;}
function stopclock(){clearInterval(se);ss=1;m=h=s=0;document.getElementById("showtime").innerHTML="0时0分0秒00毫秒";istrue=true;}
</script>
<table align="center" style="margin-top:150px;">
<tr>
<td align="center">
<h1 id="showtime" style="color:#ff0000;font-size:124px;">0时0分0秒00毫秒</h1><br/>
<input style="width:100px;height:30px;font-size:20px;" name="s" align="center" type="button" value="开始计时" onclick="startclock()">
<input style="width:100px;height:30px;font-size:20px;" name="s" align="center" type="button" value="暂停计时" onclick="pauseclock()">
<input style="width:100px;height:30px;font-size:20px;" name="s" align="center" type="button" value="重新计时" onclick="stopclock()">
</td>
</tr>
</table>
上一篇:JS一个简单实现倒计时代码
下一篇:Javascript对日期的操作,日期函数
讨论数量:0