javascript - 按钮不适用于 JS 插入的 HTML,但适用于纯 HTML
问题描述
得到了这个ToDoList 应用程序
一切都很好,但是在我插入一个新活动(一个新表)之后,即使我给了它们类并触发了eventListener
s,按钮也没有响应。
Atm,我的 DOM 常量位于 JS 页面的顶部,但即使我在 JS 页面中插入新表(活动)后移动它们,仍然无法正常工作。
tldr:
- 删除和检查按钮适用于页面上预设的 html;
- 删除和检查按钮不适用于使用 js 插入的 html
newDiv.innerHTML = `<table class="table table-dark">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Priority</th>
<th scope="col">Description</th>
<th scope="col">Date</th>
<th scope="col">Tasks</th>
<th scope="col">Completed</th>
<th scope="col">Remove</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">${newActivity.title}</th>
<td>${newActivity.priority}</td>
<td>${newActivity.description}</td>
<td>${newActivity.date}</td>
<td><i class="fas fa-sitemap"></i></td>
<td><span class ='check-button'>X</span></td>
<td><i class="fas fa-archive remove-button"></i></td>
</tr>
</tbody>
</table>`;
解决方案
推荐阅读
- apache - worker.properties 是强制在 Apache http 服务器中启用负载平衡和粘性会话的吗
- reactjs - React/Electron 不加载位于公共目录中的静态文件
- ruby-on-rails - docx 文件的回形针上传被下载为 zip 文件?
- java - 在 Aspose Words for Android 中获取段落中字符样式文本的起始位置
- python - 使用应用返回错误基于 2 列创建新列
- rabbitmq - Rabbitmq 服务器启动失败
- react-native - 在 react-native-nfc-manager v2 中禁用声音
- python - 有没有办法在输入后预先写一些东西?
- rust - Rust 为模块保留的名称
- linux-kernel - 如何卸载使用 ACPI_CONFIG_SYSFS 加载的覆盖