我正在尝试为所有访客生成/存储/显示10-45之间的数字,并且每天都在更改。
我认为它每周工作一次。
$(document).ready(function(){
var minNumber = 10;
var maxNumber = 45;
if (!localStorage.getItem("responsetime") && !localStorage.getItem("responsetime") ) {
var d = Date.now();
var RandomNum = Math.floor((Math.random()*(maxNumber-minNumber+1))+minNumber);
localStorage.setItem("responsetime",RandomNum);
localStorage.setItem("myTime",d);
}
else {
var newTime = Date.now();
var oldTime = localStorage.getItem("responsetime");
if(newTime - oldTime > 7*24*60*60*1000) {
RandomNum = Math.floor((Math.random()*(maxNumber-minNumber+1))+minNumber);
localStorage.setItem("responsetime",RandomNum);
localStorage.setItem("myTime",newTime);
}
}
$(".responsetime").text(localStorage.getItem("responsetime"))
})
我希望10-45分中的所有分值会存储在本地存储中,并且每天都会对所有访问者进行更改。