1. Follow a specific class structure layout.
2. It is necessary to introduce jquery before introducing this file.
/** * Simple Countdown * * Supports multiple timers within the page and does not interfere with each other * Usage: * * <div class= "timer-simple-seconds" timer= "3600" > * <span class= "Hour" >hour</span> hours <span class= "Minute" >minute</span> min <span class= "Secon D ">second</span> sec * </div> **/$(function(){ //all timers are processed. vartimers=$ (". Timer-simple-seconds"); for(vari=0;i<timers.length;i++){ //first call once to avoid errorsProcesstimer ($ (timers[i])); SetInterval (Processtimer,1000, $ (timers[i])); } /** * Processing time * @param {Object} timer*/ functionProcesstimer (timer) {varTotal=parseint (timer.attr ("Timer")); //The countdown cannot be negative if(total<0)return; //find the element that appears minutes and seconds varHour=timer.find (". Hour"); varMinute=timer.find (". Minute"); varSecond=timer.find (". Second"); //calculate the values that should be displayed varH=math.floor (total/(60*60));varM=math.floor (Math.floor ((total-h*60*60)/60));varS=total-h*60*60-m*60; //Fill- in if(m<10) m= "0" +m; if(s<10) s= "0" +s; //ShowHour.text (h); Minute.text (m); Second.text (s); //record values for next usetotal--; Timer.attr ("Timer", total); } });
jquery Simple Countdown Plugin