[英]how to show div one time each hour
I want to show a div only 1 time each hour with a cookie. 我想每个小时仅显示一次div和cookie。 I try to use this js but this seems to work every day 1 time, and i want every hour 1 time.
我尝试使用此js,但这似乎每天工作1次,我希望每小时工作1次。
what do i have to modify on this script? 我必须对此脚本进行哪些修改?
$(document).ready(function() {
if( $.cookie('showOnlyOne') ){
//it is still within the day
//hide the div
$('#shownOnlyOnceADay').hide();
} else {
//either cookie already expired, or user never visit the site
//create the cookie
$.cookie('showOnlyOne', 'showOnlyOne', { expires: 1 });
//and display the div
$('#shownOnlyOnceADay').show();
}
});
"Value can be a Number
which will be interpreted as days from time of creation or a Date
object"... from docs. 来自docs的“值可以是一个
Number
,它将被解释为从创建之日算起的天数或一个Date
对象”。
So you should be able to do something like 所以你应该能够做类似的事情
$(document).ready(function() {
if( $.cookie('showOnlyOne') ){
//it is still within the day
//hide the div
$('#shownOnlyOnceADay').hide();
} else {
//either cookie already expired, or user never visit the site
//create the cookie
var date = new Date(Date.now() + 3600000); // thats an hour in ms
$.cookie('showOnlyOne', 'showOnlyOne', { expires: date });
//and display the div
$('#shownOnlyOnceADay').show();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.