function timeDown(second) {
var month = '', day = '', hour = '', minute = '';
if (second >= 86400 * 30) {
month = Math.floor(second / (86400 * 30)) + '月';
second = second % (86400 * 30);
}
if (second >= 86400) {
day = Math.floor(second / 86400) + '天';
second = second % (86400);
}
if (second >= 3600) {
hour = Math.floor(second / 3600) + '小时';
second = second % 3600;
}
if (second >= 60) {
minute = Math.floor(second / 60) + '分';
second = second % 60;
}
if (second > 0) {
second = second ? second + '秒' : '';
}
return month + day + hour + minute + second;
}
<!-- 引入jquery -->
<script>
$(function () {
var second = 10000;
$('.remain_time').html(timeDown(second));
setInterval(function () {
second--;
$('.remain_time').html(timeDown(second));
}, 1000);
})
</script>
<span class="remain_time"></span>
$.fn.timeDown = function (opt) {
var second = opt.second;
var tip = '已过期';
var $this = this;
self._timeDown = function (second) {
var month = '', day = '', hour = '', minute = '';
if (second >= 86400 * 30) {
month = Math.floor(second / (86400 * 30)) + '月';
second = second % (86400 * 30);
}
if (second >= 86400) {
day = Math.floor(second / 86400) + '天';
second = second % (86400);
}
if (second >= 3600) {
hour = Math.floor(second / 3600) + '小时';
second = second % 3600;
}
if (second >= 60) {
minute = Math.floor(second / 60) + '分';
second = second % 60;
}
if (second > 0) {
second = second ? second + '秒' : '';
} else {
return tip;
}
return month + day + hour + minute + second;
};
$this.html(self._timeDown(second));
setInterval(function () {
second--;
$this.html(self._timeDown(second));
}, 1000)
};
// 使用方式
$('.remain_time').timeDown({second:1000,tip:'已过期'})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有