Javascript localstorage.getItem仅显示一个数据,尽管阵列中有多个数据
虽然数组项数组中存储了多个数据,但它仅显示最近添加的数据。这可能是什么原因? 提前感谢您的支持Javascript localstorage.getItem仅显示一个数据,尽管阵列中有多个数据,javascript,arrays,json,local-storage,Javascript,Arrays,Json,Local Storage,虽然数组项数组中存储了多个数据,但它仅显示最近添加的数据。这可能是什么原因? 提前感谢您的支持 // List items const array_item = JSON.parse(localStorage.getItem("array_item") || "[]"); array_item.forEach(function(item,index,array){ const output = '<div c
// List items
const array_item = JSON.parse(localStorage.getItem("array_item") || "[]");
array_item.forEach(function(item,index,array){
const output = '<div class="bg-card p-2" style="font-size:14px;"><div class="container"><strong>Okunmadı olarak işaretlediğin makale:</strong> <a href="<?=PROOT?>home/details/'+item.sef_link +'">'+item.title+'</a></div></div>';
console.log(array);
document.getElementById("mark").innerHTML = output;
});
//列出项目
const array_item=JSON.parse(localStorage.getItem(“array_item”)| |“[]”);
数组\项.forEach(函数(项、索引、数组){
常量输出=“Okumbadıolak işaretlediğin makale:”;
console.log(数组);
document.getElementById(“mark”).innerHTML=输出;
});
const array_item=JSON.parse(localStorage.getItem(“array_item”)| |“[]);
数组\项.forEach(函数(项、索引、数组){
常量输出=“Okumbadıolak işaretlediğin makale:”;
console.log(数组);
document.getElementById(“mark”).innerHTML+=输出;
});
您每次都在替换内容,而不是附加内容!我没有做任何改变。我只是尝试提取数组项数组中的数据。哪里出错了?document.getElementById(“mark”).innerHTML=output每次都会替换HTML,而不是附加到它!当我添加新数据时,在刷新页面之前不会看到它。为此,;那么我应该怎么做才能立即显示呢?你知道这个话题吗?
const array_item = JSON.parse(localStorage.getItem("array_item") || "[]");
array_item.forEach(function(item,index,array){
const output = '<div class="bg-card p-2" style="font-size:14px;"><div class="container"><strong>Okunmadı olarak işaretlediğin makale:</strong> <a href="<?=PROOT?>home/details/'+item.sef_link +'">'+item.title+'</a></div></div>';
console.log(array);
document.getElementById("mark").innerHTML += output;
});