我的倒计时不需要在页面刷新时重置。谁能告诉我什么最适合我目前的代码?我还想要一些输入,如果可以禁用任何类型的鼠标点击,或者如果另一个apporach是让用户在倒计时期间无法进入页面上其他位置的方式。感谢任何帮助!
我不是重复的,因为它包括在倒计时期间删除鼠标点击,我的目标与该帖子有很大不同。
var time = 30;
function countdown()
{
if(time==0)
{
window.location.reload();
}
else
{
tmptime = time;
dayTime = 24*60*60;
hourTime = 60*60;
minutesTime = 60;
days = Math.floor(tmptime/dayTime);
tmptime = tmptime - days*dayTime;
hours = Math.floor(tmptime/hourTime);
tmptime = tmptime - hours*hourTime;
minutes = Math.floor(tmptime/minutesTime);
tmptime = tmptime - minutes*minutesTime;
seconds = tmptime;
tidtext="";
if(days>0)
tidtext = days+ hours + " hours " + minutes + " minutes " + seconds + " seconds";
else if(hours>0)
tidtext = hours + " hours " + minutes + " minutes " + seconds + " seconds";
else
tidtext = minutes + " minutes " + seconds + " seconds";
document.getElementById('timer').innerHTML = tidtext;
document.getElementById('timer').classList.add('timer');
time--;
setTimeout("countdown()", 1000);
}
}
<td data-th="Workout"><input type="submit" onclick="countdown();" value="Bench Press"></td>
<div id="timer"></div>
答案 0 :(得分:0)
您可以使用localStorage。
localStorage.setItem("time", time);
会将time
的值设置为localStorage。您可以在循环的每次迭代中执行此操作。然后,在页面加载时你可以做
time = localStorage.getItem("time");
从localStorage检索time
的值。