var promotion = function () { $(".goRegistered").click(function () { window.open($(this).data("href")); }); function TimeDown(id, endDateStr) { //结束时间 var endDate = new Date(endDateStr); //当前时间 var nowDate = new Date(); //相差的总秒数 var totalSeconds = parseInt((endDate - nowDate) / 1000); //天数 var days = Math.floor(totalSeconds / (60 * 60 * 24)); //取模(余数) var modulo = totalSeconds % (60 * 60 * 24); //小时数 var hours = Math.floor(modulo / (60 * 60)); modulo = modulo % (60 * 60); //分钟 var minutes = Math.floor(modulo / 60); //秒 var seconds = modulo % 60; //输出到页面 if (days === 0 && hours === 0 && minutes === 0 && seconds === 0) { $("#" + id).html(language_data.public['已经']+language_data.public['截止']); } $("#" + id).html(days + language_data.public['天'] + hours + language_data.public['时'] + minutes + language_data.public['分钟'] + seconds + language_data.public['秒']); //延迟一秒执行自己 setTimeout(function () { TimeDown(id, endDateStr); }, 1000) } $('.countdown').each(function (i) { var id = $(this).attr("id"); var endDateStr = $(this).attr("data-promotion-end-date"); TimeDown(id, endDateStr); }); }; promotion();