按钮 chrome 扩展 class 上的事件侦听器似乎不起作用,或者侦听器的操作不起作用?

Event listeners on chrome extension class of buttons doesn't seem to work, or the action of the listener doesn't work?

我正在尝试制作一个 chrome-扩展弹出窗口-window,用户可以借此添加特定选项卡的 URL 或删除一个或全部删除。 delete all 工作正常,add URL 也可以。但是,'delete one link' 根本不起作用,我真的一直在为那个部门而苦苦挣扎。我希望有人能帮我解决这个问题,因为我不知道问题出在哪里。以下是文件:

我在其他帖子上读到,这可能是因为 getElementsByClassName 没有 return 一个 'real' 数组,您可以通过该数组使用函数来操作事物,如果这是真的,比我没有工具来解决这个问题。

'X' 按钮不起作用:

清除所有按钮按预期工作:

在您的 removeMe() 函数中,您必须从其父元素中删除 DOM 元素。像这样:

function removeMe(i) {
  // remove it from the DOM
  var list = document.getElementsByClassName('items');
  list[i].parentNode.removeChild(list[i]);
  list.splice(i, 1);

  // remove it from chrome-storage
  chrome.storage.local.get({urlList:[], titleList:[]}, function(data) {
     urlList = data.urlList;
     titleList = data.titleList;
     urlList.splice(i, 1);
     titleList.splice(i, 1);

     // update chrome storage
     saveList();
  }); 
}

或者你可以只使用你的主要 list id:

document.getElementById("list").removeChild(list[i]);