首页 > 解决方案 > 按钮不适用于 JS 插入的 HTML,但适用于纯 HTML

问题描述

得到了这个ToDoList 应用程序

一切都很好,但是在我插入一个新活动(一个新表)之后,即使我给了它们类并触发了eventListeners,按钮也没有响应。

Atm,我的 DOM 常量位于 JS 页面的顶部,但即使我在 JS 页面中插入新表(活动)后移动它们,仍然无法正常工作。

tldr:

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>`;

标签: javascript

解决方案


推荐阅读