收到一条错误消息,指出“taskOutput 不可迭代”。数组如下所示:
const taskOutput = JSON.parse(window.localStorage.getItem("taskList")) || [];
循环如下所示:
for (const task of taskOutput) {
const taskEl = document.createElement("div");
const {participant, duetime, description} = task;
// PROGRESSION-BAR
let newDiv = document.createElement("div");
let newBtn = document.createElement("button");
let btnText = document.createTextNode("Fullfør");
newBtn.appendChild(btnText);
newDiv.style.border = "3px solid black";
newDiv.style.height = "10px";
newDiv.style.backgroundColor = task.color;
newBtn.onclick = function() {
if(task.color === "red"){
task.color = "green";
localStorage.setItem('taskList', JSON.stringify(taskOutput));
}
else if(task.color === "green"){
task.color = "red";
localStorage.setItem('taskList', JSON.stringify(taskOutput));
newDiv.style.backgroundColor = task.color;
}
}
德玛西亚99
相关分类