简体   繁体   English

setinterval倒数计时无法正常工作

[英]setinterval countdown is not working properly

I have js countdown function 我有js倒计时功能

var sTime = new Date().getTime();
var countDown = 60;

function RefreshThePage() {
var cTime = new Date().getTime();
var diff = cTime - sTime;
var seconds = countDown - Math.floor(diff / 1000);
if (seconds === 0) {
    location.reload(true);
}
if (seconds >= 0) {
    var minutes = Math.floor(seconds / 60);
    seconds -= minutes * 60;
    $("#minutes").text(minutes < 10 ? "0" + minutes : minutes);
    $("#seconds").text(seconds < 10 ? "0" + seconds : seconds);
} else {
    $("#countdown").hide();

    clearInterval(counter);
}
}

and in html side , I call this 在html方面,我称此为

 RefreshThePage();
           var counter = setInterval(RefreshThePage, 1000);

the issue is , normally it should refresh the page in 60 seconds but this code refreshs the page in 30 seconds. 问题是,通常它应该在60秒内刷新页面,但是此代码在30秒内刷新页面。 I don't know where the problem is .. 我不知道问题出在哪里..

I resolved the issue 我解决了这个问题

I forgot this html meta tag in somewhere in ui side 我在ui端某处忘记了这个html meta标签

<meta http-equiv="refresh" content="30" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM