简单倒计时
/** * $.myCountdown * @extends jquery-1.6.1.min.js * @fileOverview 倒计时 * @author xws * @version 0.1 * @date 2012-04-12 * @example * */(function($){ $.fn.myCountdown= function(entTime,type,systemTime){ var showCoutdown = $(this); var sh; var endtimeStr = entTime.replace(/-/g,"/"); var endTime=new Date(endtimeStr); var nowtime = new Date(systemTime); var leftsecond=parseInt((endTime.getTime()-nowtime.getTime())/1000); sh=setInterval(function(){ fresh(entTime,sh,showCoutdown,type,leftsecond); leftsecond -= 1; },1000); }; function fresh(endDate,sh,showCoutdown,type,leftsecond){ var d = parseInt(leftsecond/3600/24); var h = parseInt((leftsecond/3600)%24); var m = parseInt((leftsecond/60)%60); var s = parseInt(leftsecond%60); switch (type){ case "li" : showCoutdown.html("<ul><li class='fist'>还剩</li><li>"+d+"天</li><li>"+h+"时</li><li>"+m+"分</li><li>"+s+"秒</li>"); break; case "span": showCoutdown.html("<span>剩余</span><b>" + d + "</b> 天<b>" + h + "</b> 时<b>" + m + "</b> 分 <b>" + s + "</b> 秒"); break; default: showCoutdown.html("剩余时间:<br /><b>"+d+"</b> 天<b>"+h+"</b> 时<b>"+m+"</b> 分 <b>"+s+"</b> 秒"); break; } if(leftsecond <= 0){ showCoutdown.html("<b>时间已结束</b>"); clearInterval(sh); } }})(jQuery);
此js依赖jquery-1.6.1.min.js
使用方法:
endTime为结束时间 格式为:yyyy-MM-dd HH:mm:ss
systemTime为系统时间?格式为:yyyy-MM-dd HH:mm:ss
type 为倒计时类型
$("#countdownTime").imallCountdown(endTime,type,systemTime);
?