我首先使用此脚本在本地存储 html 代码:
queuehistory = $("#queue").html();
localStorage.setItem("queuehistory", queuehistory);
当页面加载时,我运行一个脚本来检测是否设置了 localstorage 项:
if (localStorage.getItem("queuehistory"))
{
$("#queue").html(localStorage.getItem("queuehistory"));
}
虽然 localstorage 已经设置并且确实存在,但由于某种原因,html 代码没有被加载到 $("#queue") 中。
出于测试目的,我运行了这段代码:
if (localStorage.getItem("queuehistory"))
{
alert(localStorage.getItem("queuehistory"));
$("#queue").html(localStorage.getItem("queuehistory"));
}
localStorage.getItem 绝对不是空的,所以我不知道为什么这段代码似乎不起作用。存储本身可以工作,但将我本地存储的 html 代码加载到 div 中似乎不起作用。任何帮助将不胜感激。