0
在待办事项列表中,我正在尝试检查已关闭的项目,但我收到错误消息 - “不是对象中的空值(正在评估' itemText.style')“在没有对象的情况下评估(评估itemText.style)
任何人都可以解释我应该如何改变这一点,使罢工工作? 我也试图避免把CSS放入我的HTML文件中,如果可能的话。
function removeItem() {
var boxId = this.id.replace("boxId_", "");
var itemText = document.getElementById("item_", + boxId);
itemText.style.setProperty("text-decoration", "line-through"); //error here
}
function addNewItem(list, itemText) {
totalItems++;
var listItem = document.createElement("li");
var checkBox = document.createElement("input");
checkBox.type = "checkbox";
checkBox.id = "cb_" + totalItems;
var span = document.createElement("span");
span.id = "item_" + totalItems;
span.innerText = itemText;
checkBox.onclick = removeItem;
listItem.appendChild(checkBox);
listItem.appendChild(span);
list.appendChild(listItem);
}
var btnNew = document.getElementById("btnAdd");
var totalItems = 0;
var inItemText = document.getElementById("inItemText");
inItemText.focus();
btnNew.onclick = function() {
var itemText = inItemText.value;
if (!itemText || itemText == "") {
return false;
}
addNewItem(document.getElementById("todoList"), itemText);
};
'VAR itemText =的document.getElementById( “ITEM_” + boxId);' - 不应该有'后 “ITEM_”' –
真棒昏迷。谢谢。 –