js interval ,timeout
Posted sx00
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js interval ,timeout相关的知识,希望对你有一定的参考价值。
var inter;
intervatest("2019-08-22 09:12:00");
function intervatest(str)
ShowCountDown(str, ‘sjtest‘);
inter = window.setInterval(function ()
ShowCountDown(str, ‘sjtest‘);
, 1000);
clearInterval(inter);
function ShowCountDown(t, divname)
var now = new Date();
var endDate = new Date(t);
var leftTime = endDate.getTime() - now.getTime();
var dd = parseInt(leftTime / 1000 / 60 / 60 / 24, 10);//计算剩余的天数
var hh = parseInt(leftTime / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数
var mm = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟数
var ss = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
dd = checkTime(dd);
hh = checkTime(hh);
mm = checkTime(mm);
ss = checkTime(ss);//小于10的话加0
var cc = document.getElementById(divname);
// cc.innerhtml = "距离" + year + "年" + month + "月" + day + "日还有:" + dd + "天" + hh + "小时" + mm + "分" + ss + "秒";
if (cc != null)
cc.innerHTML = dd + ":" + hh + ":" + mm + ":" + ss;
function checkTime(i)
if (i < 10)
i = "0" + i;
return i;
以上是关于js interval ,timeout的主要内容,如果未能解决你的问题,请参考以下文章