Now e-commerce is booming. The countdown to JavaScript is widely used for flash sales and time-limited time. Next, let's look at the countdown effect first.
Effect demonstration
Code that can be written at Will is still to be improved. The source code is as follows:
JavaScript Code
<Script type = "text/javascript" language = "javascript"> // The total time. Unit: var time = 100; // hour var h = parseInt (time/60)> 0? ParseInt (time/60): 0; // minute var m = time % 60; // second var s = 60; // output to the Dom position document of the current Script. write ('<span> time-limited seckilling, remaining <font id = "f_hh"> '+ h +' </font> <font id = "f_mm"> '+ m +' </font> Points <font id = "f_ss"> '+ s +' </font> second </span> '); // start to execute the countdown var timeInterval = setInterval (function () {// if the hour, minute, and second are both 0, the current countdown will be stopped if (h = 0 & m = 0 & s = 0) {clearInterval (timeInterval); return;} // when the second reaches 0, it is 60 seconds again if (s = 0) {s = 60 ;} if (s = 60) {// every time the second reaches 60 seconds, the minute minus one m-= 1; // when the minute is equal to 0 and the hour is more than one hour, check if (m = 0 & h> 0) {// one hour minus h-= 1; // The automatic default value for minutes is 60 Minutes m = 60; // The automatic default value for seconds is 60 seconds s = 60 ;}} // seconds continue to beat, minus one s-= 1; // The Hour value is document. getElementById ('f _ hh '). innerHTML = h; // minute value: document. getElementById ('f _ mm '). innerHTML = m; // The second value is document. getElementById ('f _ ss '). innerHTML = s;}, 1000); </script>