如何使jquery倒计时计时器在刷新时不重新启动 [英] How to make a jquery count-down timer that doesn't restart on refresh
问题描述
我正在创建一个待售的网页模板,但我不能让计时器倒计时,我不知道怎么做。我需要计时器倒计时(当添加日期时,它应该减少),也不应该在刷新时间或关闭时间重新启动。请帮我做这个代码...我会在我的模板中使用它。
I am creating a web template for sale, but I can't make timer count down, I don't how to make it. I need timer count down (when a date is added, it should be decreased), also it should not restart on refresh time or shut down time. Please help me to do this code... I will use it in my template.
推荐答案
如果你没有使用数据库,然后您可以使用HTML5 localstorage。将变量存储在用户本地计算机上(如果已访问过)。页面加载时,请检查该变量的本地存储。如果它不是null,那么不要像在网站上那样初始化计时器。
If you are not working with a database, then you can use HTML5 localstorage. Store a variable on the users local machine if they have already visited. When the page loads, do a check of local storage for that variable. If it is not null, then don't init the timer as they have already been on the site.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
创建localstoreage var:
Create localstoreage var:
var myStorage = localStorage;
如果用户加载页面 - 在已访问中存储为真
If user loads page - store true in "visited"
localStorage.setItem('visited', 'true');
如果访问者重新加载页面,请检查visited == true,如果为true,则不要触发计时器。
If visitor reloads page, check for visited == true, and if true, dont trigger timer.
var hasVisited = function() {
var didVisit = myStorage.getItem('visited');
if(didVisit == "true"){
//do nothing}
}else{
//start your timer
};
这篇关于如何使jquery倒计时计时器在刷新时不重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!