首页 > 代码库 > js图片倒计时

js图片倒计时

var discountOnline = !{discountOnline}
if (discountOnline) {
_fresh()
setInterval(_fresh, 1000);
}

var nowtime = false;
function _fresh() {
var endtime = new Date("February 10, 2017 23:59:59");
if(!nowtime){
nowtime = !{dateTime};
}
var leftsecond = parseInt((endtime.getTime() - nowtime) / 1000);
nowtime = nowtime + 1000;
if (leftsecond < 0) {
leftsecond = 0;
}
var _d = parseInt(leftsecond / 3600 / 24);
var _h = parseInt((leftsecond / 3600) % 24);
if (_h < 10) {
_h = "0" + _h;
}
var _m = parseInt((leftsecond / 60) % 60);
if (_m < 10) {
_m = "0" + _m;
}
var _s = parseInt(leftsecond % 60);
if (_s < 10) {
_s = "0" + _s;
}
var _all = _d + " 天 " + _h + " 小时 " + _m + " 分 " + _s + " 秒";
_all = _all.replace(/([0-9]{1})/g, ‘<img width="9" height="16" src="http://www.mamicode.com/images/time/$1.png">‘)
$(".time").find("span").html(_all);
}

js图片倒计时