我正在做一个待办事项列表的网页,我被困在如何从列表中删除一个待办事项名称,而不删除整个事情。
const todoList = [];
function addTodo() {
const inputElement = document.querySelector('.js-input');
const todoName = inputElement.value;
if (todoName.trim() !== '') {
todoList.push(todoName);
const todoListElement = document.querySelector('.js-todo-list');
todoListElement.innerHTML += `
<li class="js-todo-items">
${todoList.length}. ${todoName}
</li>
<button class="final-button" id="button" onclick="todoFinished()">✅</button>
<button class="final-button" id="button" onclick="todoFinished()">🚫</button><br>`;
inputElement.value = '';
}
}
function clearTodo() {
todoList.length = 0;
const todoListElement = document.querySelector('.js-todo-list');
todoListElement.innerHTML = '';
}
function todoFinished(){
todoList.pend(todoName)
}
我试图使名称具有不同的属性,这样我就可以删除选定的一个,但我不知道如何做到这一点。
1条答案
按热度按时间w1e3prcc1#
你在html中显示元素时遇到了问题。显示逻辑不应该在添加逻辑。下面是重写的代码