制作秒表
1 2 3 4 | <input type= "text" name= "" id= "shuzi" value= "00:00:00" /><br /> <input onclick= "ks()" type= "button" name= "" id= "kaishi" value= "开始" /> <input onclick= "zt()" type= "button" name= "" id= "" value= "暂停" /> <input onclick= "cz()" type= "button" name= "" id= "" value= "重置" /> |
毫秒与秒之间的换算 100ms等于一秒
定义定时器10ms刷新一次 那么1秒钟刷新100次 就是毫秒 定义一个变量n n++ 那么毫秒就是n%100(取整) 取余
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。秒等于n/100%60 分等于n/6000%60
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <script> var n=0; var time= null ; function xs(){ var aaa=document.getElementById( "shuzi" ); n++; var haomiao=parseInt(n%100); var miao=parseInt(n/100%60); var fen=parseInt(n/6000%60); aaa.value=bl(fen)+ ":" +bl(miao)+ ":" +bl(haomiao) } function ks(){ //开始 clearInterval(time); time=setInterval(xs,10); //定时器 10毫秒刷新一次 } function zt(){ //暂停 clearInterval(time); //清除定时器 } function cz(){ //重置 var aaa=document.getElementById( "shuzi" ); aaa.value= "00" + ":" + "00" + ":" + "00" ; clearInterval(time); //清除定时器 } function bl(ggg){ //补零 return ggg<10? "0" +ggg: "" +ggg } </script> |

更多精彩