// JavaScript Document (function($){ $.fn.countdown=function(opts){ var $that=$(this); var options=$.extend({},$.fn.countdown.defaults,opts); function getTimes(y,m,d,h,f,s){ var oStartDate = new Date(); var oEndDate = new Date(); oEndDate.setFullYear(parseInt(y)); oEndDate.setMonth(parseInt(m)-1); oEndDate.setDate(parseInt(d)); oEndDate.setHours(h); oEndDate.setMinutes(f); oEndDate.setSeconds(s); iRemain = (oEndDate.getTime() - oStartDate.getTime())/1000; var times=iRemain/(60*60*24); var days=Math.floor(iRemain/(60*60*24)); var hours=Math.floor((times-days)*24); var minutes=Math.floor(((times-days)*24-hours)*60); var seconds=Math.round(((((times-days)*24-hours)*60)-minutes)*60); $that.text(days + "天" + hours + "时" + minutes + "分" + seconds + "秒"); } setInterval(function(){getTimes(options.y,options.m,options.d,options.h,options.f,options.s)},1000); } })(jQuery); $.fn.countdown.defaults={ y:2012, m:6, d:20, h:12, f:0, s:0 }