½üÆÚÔÚ×öÅÅÁÐÎåµÄ²ÊƱÏîÄ¿£¬Ã¿Ò»ÆÚ¶¼Óйº²Êʱ¶Î£¬¼´Óû§´ò¿ªÕâ¸öÅÅÁÐÎåµÄÒ³Ãæʱ£¬»á´Ó·þÎñÆ÷´«À´Ò»¸öremaintime£¨Àë±¾´Î²ÊÆÚ½áÊøµÄÊ£Óàʱ¼ä£©£¬È»ºóÕâ¸öʱ¼äÔÚ¿Í»§¶ËµÝ¼õ³ÊÏÖ¸øÓû§¿´£¬ÈÃÓû§»ñµÃ±¾´Î²ÊÆÚµÄÊ£Óàʱ¼ä¡£
ʵÏÖÔÀíͦ¼òµ¥µÄ£¬Ôڴ˲»ÔÚ׸Êö£¬ÔËÐÐÒÔÏ´úÂë²é¿´demo£º
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>index</title> <style type="text/css"> em{color:#f00;} </style> </head> <body> <div id="remaintime"></div> <script type="text/javascript"> var TheTime = function(){ this.init.apply(this,arguments); }; TheTime.prototype = { init: function(obj){ var that = this; obj = that.buildParam(obj); that.callback = obj.callback; var container = that.container = document.getElementById(obj.container); container[removed] = '<em></em>Сʱ<em></em>·ÖÖÓ<em></em>Ãë'; var hourSpace = that.hourSpace = container.getElementsByTagName('em')[0]; var minuteSpace = that.minuteSpace = container.getElementsByTagName('em')[1]; var secondSpace = that.secondSpace = container.getElementsByTagName('em')[2]; if(obj.remaintime==0){ that.resetTime(); return; } that.hours = Math.floor(obj.remaintime/3600); that._remainder1 = obj.remaintime % 3600; that.minutes = Math.floor(that._remainder1/60); that.seconds = that._remainder1 % 60; var timer = that.timer = setInterval(function(){ that.renderTime.apply(that); },1000); }, buildParam: function(obj){ obj = { //containerΪdom½ÚµãµÄid container: obj.container || 'container', remaintime: Number(obj.remaintime) || 0, //µ¹¼ÆʱÍê³ÉºóµÄ»Øµ÷ callback: obj.callback || new Function }; return obj; }, resetTime: function(){ var that = this; that.container[removed] = "ÒѾ½ØÖ¹"; }, //Ë¢ÐÂʱ¼ä renderTime: function(){ //debugger; var that = this; if(that.seconds>0){ that.seconds--; }else{ that.seconds = 59; if(that.minutes>0){ that.minutes--; }else{ that.minutes = 59; if(that.hours>0){ that.hours--; } } } //ʱ¿Ì¼àÌý if(that.hours==0 && that.minutes==0 && that.seconds==0){ //Ö´Ðлص÷ that._callback(); } var bitHandle = that.bitHandle; var _hour = bitHandle(that.hours); var _minute = bitHandle(that.minutes); var _second = bitHandle(that.seconds); that.hourSpace[removed] = _hour; that.minuteSpace[removed] = _minute; that.secondSpace[removed] = _second; }, //¶ÔÓÚλÊýµÄ´¦Àí£¬È·±£·µ»ØÁ½Î»Êý bitHandle: function(num){ var str = num.toString(); if(str.length<2){ str = 0 + str; } return str; }, _callback: function(){ var that = this; clearInterval(that.timer); that.callback(); } }; new TheTime({ //ÈÝÆ÷id container: 'remaintime', //·þÎñÆ÷·µ»ØµÄÊ£Óàʱ¼ä£¬µ¥Î»ÎªÃë remaintime: 10000, //µ¹¼ÆʱÍê³ÉʱµÄ»Øµ÷ callback: function(){ document.getElementById('remaintime')[removed] = 'ÒѽØÖ¹'; } }); </script> </body> </html>
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ