不好意思,我可以再次寻求帮助吗,但当检查其中一个列表,然后将其设置为完成= 1时,这仍然是一个错误。
但仍然重要的是,已检查的列表位于hps上(单击时我还添加了dg按钮,它将删除列表),然后完成td msh = 1,当删除时,列表将影响较早完成所以= 0
但是为什么不起作用,在btnDel函数部分
<div id="myDIV" class="header">
<div class="input-group">
<input type="text" class="form-control" placeholder="Your Text..."id="todo-input">
<div class="input-group-append">
<button class="btn btn-default input-group-text" id="todo-btn-add">Add</button>
</div>
</div>
</div>
<p class="text-danger d-none" id="alert">You must write something !</p>
</div>
<p class="count-todo-completed">Completed : <span id="number">0</span></p>
<ul class="list-group" id="todo-list-items"></ul>
let renderItems = () => {
DOMStrings.listItems.innerHTML = '';
var ac;
items.data.map((item, index) => {
if (item.check) {
ac = `
<li class="list-group-item" index="${index}">
<div class="form-check">
<input type="checkbox" class="form-check-input" checked onchange="onChecked(this);">
<label class="form-check-label"><strike>${item.name}</strike></label>
</div>
<span onclick="btnDel(this);">X</span>
</li>
`
} else {
ac = `
<li class="list-group-item" index="${index}">
<div class="form-check">
<input type="checkbox" class="form-check-input" onchange="onChecked(this);">
<label class="form-check-label">${item.name}</label>
</div>
<span onclick="btnDel(this);">X</span>
</li>`
}
DOMStrings.listItems.innerHTML += ac;
})
}
//count "completed"
let count = () => {
var number = 0;
for (index in items.data) {
if (items.data[index].check) {
number++;
}
}
items.completed = number;
DOMStrings.countTodoCompleted.innerHTML = number;
}
// Create a "close" button and append it to each list item
let btnDel = (e) => {
const index = e.parentElement.getAttribute("index");
if(btnDel.addEventListener("click", function(){
number--
}));
DOMStrings.countTodoCompleted.innerHTML = number;
e.parentElement.remove();
items.data.splice(index, 1);
localStorage.setItem('items', JSON.stringify(items));
}