Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function toggleDone(e) {
- // 只針對 checkbox 的事件做比對
- if (!e.target.matches("input")) return; // skip this unless it's an input
- // 取得 checkbox 的 data-index 值
- const el = e.target;
- const index = el.dataset.index;
- // 改動 done 這項資料的 flag
- items[index].done = !items[index].done;
- // 存入更動後的資料
- localStorage.setItem("items", JSON.stringify(items));
- // 重新載入
- populateList(items, itemsList);
- }
- // 監聽事件
- itemsList.addEventListener("click", toggleDone);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement