更新时间:2023-12-03 09:02:46
Use localStorage()
.
Local storage is per origin (per domain and protocol)
localStorage
as localStorage.setItem('desiredTime', time)
localStorage.getItem('desiredTime')
, based on that show/hide
jQuery
$(document).ready(function(){
//Get current time
var currentTime = new Date().getTime();
//Add hours function
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;
}
//Get time after 24 hours
var after24 = new Date().addHours(10).getTime();
//Hide div click
$('.hide24').click(function(){
//Hide div
$(this).hide();
//Set desired time till you want to hide that div
localStorage.setItem('desiredTime', after24);
});
//If desired time >= currentTime, based on that HIDE / SHOW
if(localStorage.getItem('desiredTime') >= currentTime)
{
$('.hide24').hide();
}
else
{
$('.hide24').show();
}
});
HTML
<div>DIV-1</div>
<div class='hide24'>DIV-2</div>
Things to note
$.cookie
as well, but that's an older approach now.<div>
with class hide24
will be hidden only.localStorage
, you should have HTML5 browsers.Hope this helps.