js 简单倒计时插件和使用方法
// 倒计时插件 (function (){ function countdown(config){ var startDate = config.start ? new Date(config.start) : new Date(); var endDate = new Date(config.end); var id = config.id || 'countdown'; var time = (endDate - startDate)/1000; if(time < 0){ if(config.callback){ config.callback(); } return; } var day = parseInt(time/86400, 10); var hour = parseInt(time%86400/60/60, 10); var minute = parseInt(time%86400%3600/60, 10); var second = parseInt(time%86400%3600%60, 10); var mayday = day > 0?day+'天':''; var mayhour = hour<10?'0'+hour:hour; var mayminute = minute<10?'0'+minute : minute; var maysecond = second<10?'0'+second : second; setTimeout(function (){ document.getElementById(id).innerHTML = mayday+mayhour+':'+mayminute+':'+maysecond; countdown(config); }, 1000); } window.countdown = countdown; })(); // 引用倒计时 countdown({ 'end':'2016/6/6 19:19:00', 'callback':function () { // document.getElementById('countdown').innerHTML = 'the end!'; $('.login_award_time').remove(); } });