我将计时器存储在会话存储中,因此在页面刷新时不会重置。但它不起作用。我不知道它为什么不起作用。
这里是计时器的代码以及我如何存储在会话存储中。也许我存储它有问题?
<div id="content" wicket:id="template" class="">
</div>
答案 0 :(得分:0)
It is happening because the line
sessionStorage.setItem('deadline', new Date(Date.parse(new Date() ) + (40* 60 * 1000)));
gets executed again on refresh and the deadline gets updated with the new timeStamp.
You can do it like --
if(!sessionStorage.getItem('deadline')){
sessionStorage.setItem('deadline', new Date(Date.parse(new Date() ) + (40* 60 * 1000)));
}