gpt4 book ai didi

javascript - 每次重新加载页面时阻止此脚本重置

转载 作者:行者123 更新时间:2023-11-28 16:18:32 27 4
gpt4 key购买 nike

我一直在搜索,但无法使该脚本在重新加载页面后停止重置。

该脚本每 x 小时对计时器进行一次倒计时。问题是每次重新加载页面时计时器都会重置。

有人可以帮助我如何在页面重新加载的情况下保持倒计时吗?

我用 来调用计时器。示例定时器 8:>div...etc id="timeLeft8"

    <script type="text/javascript">
var events = new Array();

events[1]={name: 'Blood Castle:', startUp: new Array(
{hour:0,minute:25},
{hour:2,minute:25},
{hour:4,minute:25},
{hour:6,minute:25},
{hour:8,minute:25},
{hour:10,minute:25},
{hour:12,minute:25},
{hour:14,minute:25},
{hour:16,minute:25},
{hour:18,minute:25},
{hour:20,minute:25},
{hour:22,minute:25}
)}

events[2]={name: 'Devil Square:', startUp: new Array(
{hour:1,minute:55},
{hour:3,minute:55},
{hour:5,minute:55},
{hour:7,minute:55},
{hour:9,minute:55},
{hour:11,minute:55},
{hour:13,minute:55},
{hour:15,minute:55},
{hour:17,minute:55},
{hour:19,minute:55},
{hour:21,minute:55},
{hour:23,minute:55}
)}

events[3]={name: 'Chaos Castle:', startUp: new Array(
{hour:0,minute:55},
{hour:2,minute:55},
{hour:4,minute:55},
{hour:6,minute:55},
{hour:8,minute:55},
{hour:10,minute:55},
{hour:12,minute:55},
{hour:14,minute:55},
{hour:16,minute:55},
{hour:18,minute:55},
{hour:20,minute:55},
{hour:22,minute:55}
)}

events[4]={name: 'Red Dragon:', startUp: new Array(
{hour:0,minute:0},
{hour:2,minute:0},
{hour:4,minute:0},
{hour:6,minute:0},
{hour:8,minute:0},
{hour:10,minute:0},
{hour:12,minute:0},
{hour:14,minute:0},
{hour:16,minute:0},
{hour:18,minute:0},
{hour:20,minute:0},
{hour:22,minute:0}
)}

events[5]={name: 'Gold Invasion:', startUp: new Array(
{hour:0,minute:0},
{hour:2,minute:0},
{hour:4,minute:0},
{hour:6,minute:0},
{hour:8,minute:0},
{hour:10,minute:0},
{hour:12,minute:0},
{hour:14,minute:0},
{hour:16,minute:0},
{hour:18,minute:0},
{hour:20,minute:0},
{hour:22,minute:0}
)}

events[6]={name: 'White Wizard:', startUp: new Array(
{hour:0,minute:0},
{hour:2,minute:0},
{hour:4,minute:0},
{hour:6,minute:0},
{hour:8,minute:0},
{hour:10,minute:0},
{hour:12,minute:0},
{hour:14,minute:0},
{hour:16,minute:0},
{hour:18,minute:0},
{hour:20,minute:0},
{hour:22,minute:0}
)}

events[7]={name: 'Blue:', startUp: new Array(
{hour:0,minute:40},
{hour:1,minute:40},
{hour:2,minute:40},
{hour:3,minute:40},
{hour:4,minute:40},
{hour:5,minute:40},
{hour:6,minute:40},
{hour:7,minute:40},
{hour:8,minute:40},
{hour:9,minute:40},
{hour:10,minute:40},
{hour:11,minute:40},
{hour:12,minute:40},
{hour:13,minute:40},
{hour:14,minute:40},
{hour:15,minute:40},
{hour:16,minute:40},
{hour:17,minute:40},
{hour:18,minute:40},
{hour:19,minute:40},
{hour:20,minute:40},
{hour:21,minute:40},
{hour:22,minute:40},
{hour:23,minute:40},
{hour:24,minute:40}
)}

events[7]={name: 'Hide&Seek:', startUp: new Array(
{hour:0,minute:42},
{hour:1,minute:22},
{hour:2,minute:32},
{hour:3,minute:42},
{hour:4,minute:52},
{hour:6,minute:02},
{hour:7,minute:12},
{hour:8,minute:22},
{hour:9,minute:32},
{hour:10,minute:42},
{hour:11,minute:52},
{hour:13,minute:02},
{hour:14,minute:12},
{hour:15,minute:22},
{hour:16,minute:32},
{hour:17,minute:42},
{hour:18,minute:52},
{hour:20,minute:02},
{hour:21,minute:12},
{hour:22,minute:22},
{hour:23,minute:32}
)}

events[8]={name: 'Sky:', startUp: new Array(
{hour:1,minute:5},
{hour:4,minute:5},
{hour:7,minute:5},
{hour:10,minute:5},
{hour:13,minute:5},
{hour:16,minute:5},
{hour:19,minute:5},
{hour:23,minute:5}
)}

events[9]={name: 'Boss Attack:', startUp: new Array(
{hour:1,minute:50},
{hour:4,minute:50},
{hour:7,minute:50},
{hour:10,minute:50},
{hour:13,minute:50},
{hour:16,minute:50},
{hour:23,minute:50}
)}


events[10]={name: 'Happy Hour:', startUp: new Array(
{hour:5,minute:5},
{hour:2,minute:5},
{hour:8,minute:5},
{hour:11,minute:5},
{hour:14,minute:5},
{hour:17,minute:5},
{hour:20,minute:5},
{hour:0,minute:5}
)}

events[11]={name: 'Hit and Up:', startUp: new Array(
{hour:0,minute:20},
{hour:2,minute:20},
{hour:5,minute:20},
{hour:8,minute:20},
{hour:11,minute:20},
{hour:14,minute:20},
{hour:20,minute:20}
)}

events[12]={name: 'Raklion:', startUp: new Array(
{hour:0,minute:15},
{hour:3,minute:15},
{hour:6,minute:15},
{hour:9,minute:15},
{hour:12,minute:15},
{hour:15,minute:15},
{hour:18,minute:15},
{hour:21,minute:15}
)}

events[13]={name: 'Moss:', startUp: new Array(
{hour:3,minute:35},
{hour:7,minute:35},
{hour:11,minute:35},
{hour:15,minute:35},
{hour:19,minute:35},
{hour:23,minute:35}
)}

events[14]={name: 'Illusion Temple:', startUp: new Array(
{hour:0,minute:25},
{hour:1,minute:25},
{hour:2,minute:25},
{hour:3,minute:25},
{hour:4,minute:25},
{hour:5,minute:25},
{hour:6,minute:25},
{hour:7,minute:25},
{hour:8,minute:25},
{hour:9,minute:25},
{hour:10,minute:25},
{hour:11,minute:25},
{hour:12,minute:25},
{hour:13,minute:25},
{hour:14,minute:25},
{hour:15,minute:25},
{hour:16,minute:25},
{hour:17,minute:25},
{hour:18,minute:25},
{hour:19,minute:25},
{hour:20,minute:25},
{hour:21,minute:25},
{hour:22,minute:25},
{hour:23,minute:25},
{hour:24,minute:25}
)}

events[15]={name: 'Castle Deep:', startUp: new Array(
{hour:1,minute:25},
{hour:7,minute:25},
{hour:13,minute:25},
{hour:19,minute:25}
)}

events[16]={name: 'CryWolf:', startUp: new Array(
{hour:1,minute:45},
{hour:4,minute:45},
{hour:7,minute:45},
{hour:10,minute:45},
{hour:13,minute:45},
{hour:16,minute:20},
{hour:19,minute:45},
{hour:22,minute:45}
)}

var curTime=1336998502
var dateTime=1336953600
function timeLeft(i){
for(j in events[i].startUp){
tmp=events[i].startUp[j].hour*3600+events[i].startUp[j].minute*60
if(dateTime+tmp>curTime){
return dateTime+tmp-curTime;
}
}
tmp=events[i].startUp[0].hour*3600+events[i].startUp[0].minute*60
return dateTime+86400+tmp-curTime;
}

function getFormatedLeftTime($seconds){
$second = $seconds % 60;
$minutes = parseInt(($seconds / 60) % 60);
$hour = parseInt(($seconds / 3600) % 24);
$days = parseInt($seconds / (24 * 3600));

$ret = '';
if ($days > 0)
if ($days == 1) $ret += '1 day ';
else $ret += $days + ' days ';


if ($hour > 0){
if ($hour < 10) $hour = '0' + $hour;
$ret += $hour + ':';
}else if ($days > 0) $ret += '00:';

if($minutes < 10) $minutes = '0' + $minutes;

$ret += $minutes + ':';

if ($second < 10) $second = '0' + $second;

$ret += $second;
return $ret;

}

function updateTimes(){
curTime++;
for (i in events){
document.getElementById("timeLeft"+i).innerHTML=getFormatedLeftTime(timeLeft(i));
}
}

for(i in events)
document.getElementById("eventList").innerHTML+="<div style='float:right; color: #FFFF00;' id='timeLeft"+i+"'>"+getFormatedLeftTime(timeLeft(i))+"</div><div style=\"color: #00FFFF;\"><strong>"+events[i].name+"</strong></div>";
setInterval("updateTimes()", 1000);



</script>

最佳答案

欢迎,javascript和html是无状态的,每个页面都是新的一天。

虽然您用 cookie 标记了您的问题,但您没有使用它,所以...使用它。
无论如何,这些事情应该在服务器端,而不是客户端。

关于javascript - 每次重新加载页面时阻止此脚本重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10584953/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com