这是网站,如果您在底部向下滚动,您会注意到所有东西都是不可见的:这可能与DOM与LocalStorage的冲突有关。
当您与setter一起访问页面并返回到主页时,您将注意到内容正在返回。
这是我的代码:
带有setters (父文件)的页面:
//code is at the end of the body of the page
localStorage.setItem("tit1",$('#r1c1Title').text());
localStorage.setItem("tit2",$('#r1c2Title').text());
localStorage.setItem("l1",document.getElementById("r1c1Link").href);
localStorage.setItem("l2",document.getElementById("r1c2Link").href);
localStorage.setItem("im1",$('#r1c1Image').attr('src'));
localStorage.setItem("im2",$('#r1c2Image').attr('src'));
custom.js
包含在每个其他html文件中:
//Retrieve Titles
var result = localStorage.getItem("tit1");
var result2 = localStorage.getItem("tit2");
//Retrieve Links
var r3= localStorage.getItem("l1");
var r33= localStorage.getItem("l2");
//Retrieve Image SRCs
var r4 = localStorage.getItem("im1");
var r44 = localStorage.getItem("im2");
//print titles
$("#ti1").html(result);
$("#ti2").html(result2);
//print links
$("#link1").attr("href", r3);
$("#link2").attr("href", r33);
//print images
$("#img1").attr("src",r4);
$("#img2").attr("src",r44);
发布于 2017-07-31 00:27:05
您没有在索引页中设置存储中的项,但在其他页中设置了项。在索引页面中,您只使用了custom.js
,它似乎是在获取项,而不是设置。因此,您所做的流程是,从索引页(不存在)从存储中获取项,然后只将项设置为来自其他页面的存储(当然,用户可以看到他第二次访问索引页)。您需要先设置项目。
https://stackoverflow.com/questions/45409988
复制