我制作了一个“bol”类的按钮列表:
const bollen = document.querySelectorAll('button.bol');
使用 console.log(bollen) 我得到:[button.bol.bolkleur, button.bol.bolkleur, button.bol.bolkleur, button.bol.bolkleur]
我做了一个点击事件监听器,想知道我点击的项目列表中的索引是什么,但得到错误:Uncaught TypeError: bollen.indexOf is not a function。但我不明白为什么,因为我见过看起来一样的例子。我的代码如下:
bollen.forEach(function (bol) {
bol.addEventListener('click', function (e) {
const gekozenBol = bollen.indexOf(bol);
console.log(`gekozen bol is ${gekozenBol}`);
});
});
谁能帮我看看我做错了什么?我仅限于一组代码,因为该项目必须使用我们学到的东西。谢谢你