私は、入力を受け取り、その下にあるチェックリストを使ってテキストを表示します。私はアイテムを削除する各アイテムにボタンを追加する方法を理解しようとしています。リストの中のチェックボックス項目を削除する
function onReady() {
const addToDoForm = document.getElementById('addToDoForm');
const newToDoText = document.getElementById('newToDoText');
const toDoList = document.getElementById('toDoList');
addToDoForm.addEventListener('submit', event => {
event.preventDefault();
let title = newToDoText.value;
let newLi = document.createElement('li');
let checkbox = document.createElement('input');
checkbox.type = "checkbox";
newLi.textContent = title;
newLi.appendChild(checkbox);
toDoList.appendChild(newLi);
newToDoText.value = '';
});
}
window.onload = function() {
alert("The window has loaded!");
onReady();
};
<form id="addToDoForm">
<label for="newToDoText">New To-Do:</label>
<input type="text" id="newToDoText">
<button type="submit">Add To-Do!</button>
</form>
<ul id="toDoList">
</ul>
<script src="app.js"></script>
* "意見はありますか?" - 意見に基づく質問は、StackOverflowの話題にはなりません。とにかく、表示されたコードでは、ネストされた要素を作成し、イベントハンドラをバインドする方法を示していますので、そのバージョンを使用してクリックハンドラでボタンを作成してください... – nnnnnn