Phiên bản đầy đủ: jsB@nk » Thời gian » Bộ đếm » Hai loại đồng hồ bấm giờ
URL: https://www.javascriptbank.com/a-stopwatch-and-a-countdown-timer.html
Hiệu ứng tạo hai đồng hồ bấm giờ với thời gian tăng và giảm, bạn có thể cho từng cái hoặc cả hai cùng chạy.
Phiên bản đầy đủ: jsB@nk » Thời gian » Bộ đếm » Hai loại đồng hồ bấm giờ
URL: https://www.javascriptbank.com/a-stopwatch-and-a-countdown-timer.html
<SCRIPT language=JavaScript><!-- Beginvar up,down;var min1,sec1;var cmin1,csec1,cmin2,csec2;function Minutes(data) {for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;return(data.substring(0,i)); }function Seconds(data) {for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;return(data.substring(i+1,data.length)); }function Display(min,sec) {var disp;if(min<=9) disp=" 0";else disp=" ";disp+=min+":";if(sec<=9) disp+="0"+sec;else disp+=sec;return(disp); }function Up() {cmin1=0;csec1=0;min1=0+Minutes(document.sw.beg1.value);sec1=0+Seconds(document.sw.beg1.value);UpRepeat(); }function UpRepeat() {csec1++;if(csec1==60) { csec1=0; cmin1++; }document.sw.disp1.value=Display(cmin1,csec1);if((cmin1==min1)&&(csec1==sec1)) alert("Stopwatch Stopped");else up=setTimeout("UpRepeat()",1000); }function Down() {cmin2=1*Minutes(document.sw.beg2.value);csec2=0+Seconds(document.sw.beg2.value);DownRepeat(); }function DownRepeat() {csec2--;if(csec2==-1) { csec2=59; cmin2--; }document.sw.disp2.value=Display(cmin2,csec2);if((cmin2==0)&&(csec2==0)) alert("Countdown Stopped");else down=setTimeout("DownRepeat()",1000); }// End --></SCRIPT><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<FORM name=sw><TABLE width="100%" border=0> <TBODY> <TR align=middle> <TD> <TABLE width="100%" border=3> <TBODY> <TR> <TH bgColor=#deb887 colSpan=2>Stopwatch</TH></TR> <TR align=middle> <TD>Stop at<BR><INPUT size=7 value=0:10 name=beg1></TD> <TD><INPUT onclick=Up() type=button value=Start></TD></TR> <TR align=middle> <TD bgColor=#deb887 colSpan=2><INPUT size=9 name=disp1></TD></TR></TBODY></TABLE></TD> <TD><INPUT onclick=Up();Down() type=button value="Start Both"></TD> <TD> <TABLE width="100%" border=3> <TBODY> <TR> <TH bgColor=#deb887 colSpan=2>Countdown</TH></TR> <TR align=middle> <TD>Start at<BR><INPUT size=7 value=0:10 name=beg2></TD> <TD><INPUT onclick=Down() type=button value=Start></TD></TR> <TR align=middle> <TD bgColor=#deb887 colSpan=2><INPUT size=9 name=disp2></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->