更新时间:2020-06-30 09:41:36
函数使用
countdown(new date('2021/06/08 18:00'),'#test');//第一个参数是结束倒计时时间戳,第二个参数是需要展示倒计时的元素(jquery选择器规则)函数参数说明
-starttime 倒计时结束时间戳(举例new date('2021/06/08 18:00'))
-select jquery选择器 页面展示倒计时的元素(举例'#test')
函数解释
function countdown(starttime,select){
setinterval(function () { //每隔一秒更新一次显示
var nowtime = new date(); //获取当前时间
var time = starttime - nowtime; //需要倒计时的时间戳
var day = parseint(time / 1000 / 60 / 60 / 24); //倒计时几天
var hour = parseint(time / 1000 / 60 / 60 % 24); //倒计时小时
var minute = parseint(time / 1000 / 60 % 60); //倒计时分钟
var seconds = parseint(time / 1000 % 60); //倒计时秒
$(select).html('<span>'+day+'</span> 天 <span>'+hour+'</span> 时 <span>'+minute+'</span> 分 <span>'+seconds+'</span> 秒');//输出样式可自定义修改
}, 1000);
}