Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. function toggleDone(e) {
  2. // 只針對 checkbox 的事件做比對
  3. if (!e.target.matches("input")) return; // skip this unless it's an input
  4. // 取得 checkbox 的 data-index 值
  5. const el = e.target;
  6. const index = el.dataset.index;
  7. // 改動 done 這項資料的 flag
  8. items[index].done = !items[index].done;
  9. // 存入更動後的資料
  10. localStorage.setItem("items", JSON.stringify(items));
  11. // 重新載入
  12. populateList(items, itemsList);
  13. }
  14.  
  15. // 監聽事件
  16. itemsList.addEventListener("click", toggleDone);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement