テキストの横にあるチェックボックスをクリックするとテキストを外していますが、何らかの理由で次の要素をすべて横切ります私は1つだけをクリックしました。イベントハンドラを使用していましたが、何らかの理由で動作しません。どんな助力も非常に感謝しています。あなたは、単純なHTML/CSSでこれを行うことができますおかげチェックボックスToDoリストのcheckBoxをクリックしたときにテキストを外す方法
function myFunction() {
var item = document.getElementById("todoInput").value
var checkBox = document.createElement("input");
checkBox.type = "checkbox";
checkBox.id = "checkbox"
checkBox.onclick = updateItem
var text = document.createTextNode(item)
var newItem = document.createElement("li")
newItem.className = "addedClass"
newItem.appendChild(text)
if (item === "") {
alert("please fill in the blanks");
} else {
var crap = document.getElementById("todoList")
crap.appendChild(newItem)
var addhere = document.getElementById("todoList")
addhere.appendChild(checkBox);
}
function updateItem() {
if (document.getElementById("checkbox").checked) {
document.getElementById("todoList").style.textDecoration = "line-through"
}
}
}
<form name="myForm" id="todoForm">
<input id="todoInput" name="fname" required>
<button type="button" onclick="myFunction()">OK</button>
</form>
<ol id="todoList"></ol>
ここに述べたようにしてみhttp://stackoverflow.com/a/30975750/4813148 – Rajesh
可能な重複チェックボックスに取り消し線を追加](http://stackoverflow.com/questions/30975459/add-strikethrough-to-checked-checkbox) – Rajesh