【发布时间】:2021-04-28 05:28:14
【问题描述】:
这是我正在创建的一个基本的 todoList 应用程序。请帮我解决这个问题,删除图标不可见。
HTML 文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>TodoList</title>
</head>
<body>
<div class="app_container">
<header>
<h2>Todo List</h2>
</header>
<main>
<input
onkeydown="if(event.keyCode==13){ todoList(); return false;} "
type="text"
placeholder="Enter your task..."
/>
<ul class="list">
<!--All your todos go here-->
</ul>
</main>
</div>
<script src="index.js"></script>
</body>
</html>
Index.js
在下面的文件中,我尝试使用 creatElement 添加一个跨度标签,该标签又包含带有垃圾元素的 。但是当我运行实时服务器时它没有显示。请帮助
function todoList() {
const list = document.querySelector('.list');
const input = document.querySelector('input');
const newTask = document.createElement('li');
const span = document.createElement('span');
span.innerHTML = '<i class="fas fa-trash"></i>';
if (input.value !== "") {
newTask.textContent = input.value;
input.value = "";
list.appendChild(newTask);
newTask.appendChild(span);
}
span.addEventListener('click', function () {
const parent = this.parentNode;
parent.removeChild();
})
newTask.addEventListener('click', () => {
newTask.classList.toggle('completed');
});
}
【问题讨论】:
标签: javascript icons