teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追加

2022/06/17 02:03

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア37488

answer CHANGED
@@ -91,4 +91,8 @@
91
91
 
92
92
  return temp.content.children;
93
93
  },
94
+ ```
95
+
96
+ ```js
97
+ tr.append(...colors[i].showInfo());
94
98
  ```

1

コメントを受けて追記

2022/06/17 02:02

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア37488

answer CHANGED
@@ -69,3 +69,26 @@
69
69
   `window.onload = function () {...}`内のコードは、ページの読み込みが終わってから実行されますので、トップレベルにあるコードの後に実行されるはずです。
70
70
 
71
71
   ステップ実行をするなどしてコードの実行順について理解を深めるのがいいかと思います。devtools の使い方は大丈夫ですか?
72
+
73
+ ---
74
+
75
+ ### コメントを受けて追記
76
+
77
+ ```js
78
+ showInfo() {
79
+ const temp = document.createElement('template');
80
+
81
+ temp.innerHTML = `<td>${this.en}</td><td>${this.ja}</td><td><button class="btn">削除</button></td>`;
82
+ const btn = temp.content.querySelector('.btn');
83
+ btn.addEventListener('click', e => {
84
+ // localStorage.removeItem(words[i][0]);
85
+ // localStorage.removeItem(words[i][1]);
86
+ if (window.confirm('本当に削除しますか?')) {
87
+ let parent = e.target.closest('tr');
88
+ parent.remove();
89
+ }
90
+ });
91
+
92
+ return temp.content.children;
93
+ },
94
+ ```