1
我想存儲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);