我正在尝试存储specSize
,specTitle
并且specURL
在会话存储的表中,将在不同的页面中使用它。在加载时,我会看到会话数据,但如果我尝试通过单击按钮将项目添加到会话存储中,它会清除现有项目并放置新项目,而不是将 onclick 项目附加到现有项目。
这是我的代码:
window.specSize;
window.specTitle;
window.specURL;
function specInfo (sSize, sTitle, sURL){
this.specSize = sSize;
this.specTitle = sTitle;
this.specURL = sURL;
}
var specArr = []
$('.flag-bookmarks a').on("click",function(e){
e.preventDefault();
specSize = $(this).parent().parent().parent().find("td:first").html();
specTitle = $(this).parent().parent().parent().find("td:nth-child(2) a").html();
specURL=$(this).parent().parent().parent().find("td:nth-child(2) a").attr("href");
specArr.push(new specInfo(specSize,specTitle,specURL))
sessionStorage.setItem('storedInfo', JSON.stringify(specArr));
});
storedValue = JSON.parse(sessionStorage.getItem('storedInfo'));
alert(storedValue);