jquery倒计时函数

2055
HTML:
<li class="mui-table-view-cell mui-media mui-col-xs-6">
            <a>
            <div class="cou-bor">
                <img class="mui-media-object" src="img/cou-1.jpg">
                <div class="cou-remark">
                    <i></i>
                    <h5>满100元减20元</h5>
                    <p id="cou-time-1" data-time="2017/1/22 20:01:00">剩下:<span class="day">-</span>天<span class="hour">-</span>时<span class="minute">-</span>分<span class="second">-</span>秒</p>
                </div>
                <div class="cou-bottom">
                    <span>剩余88份</span>
                    <span class="ajax-go">立即领取</span>
                </div>
            </div>    
            </a>
</li>
<script type="text/javascript">
/**
 * 倒计时函数
 * @param  {[type]} time        [自定义时间 格式:2017/1/26 08:25:52]
 * @param  {[type]} day_elem    [天]
 * @param  {[type]} hour_elem   [时]
 * @param  {[type]} minute_elem [分]
 * @param  {[type]} second_elem [秒]
 * @return {[type]} 
 * @author [xiaoke]
 */
function countDown(time,day_elem,hour_elem,minute_elem,second_elem){
var end_time = new Date(time).getTime(),//月份是实际月份-1
sys_second = (end_time-new Date().getTime())/1000;
var timer = setInterval(function(){
if (sys_second > 0) {
sys_second -= 1;
var day = Math.floor((sys_second / 3600) / 24);
var hour = Math.floor((sys_second / 3600) % 24);
var minute = Math.floor((sys_second / 60) % 60);
var second = Math.floor(sys_second % 60);
day_elem && $(day_elem).text(day);//计算天
$(hour_elem).text(hour<10?"0"+hour:hour);//计算小时
$(minute_elem).text(minute<10?"0"+minute:minute);//计算分
$(second_elem).text(second<10?"0"+second:second);// 计算秒
} else { 
clearInterval(timer);
}
}, 1000);
}
$(function(){
//执行函数
$(".coupon ul li").each(function (i,ke) {
i += 1;
var time = $(ke).find(".cou-remark p").attr("data-time");
countDown(time,"#cou-time-"+i+" .day","#cou-time-"+i+" .hour","#cou-time-"+i+" .minute","#cou-time-"+i+" .second");
});
});
</script>