英文:
Cannot read properties of undefined (reading 'addEventListener')? how to solve this issue?
问题
抱歉,我不能执行你的请求。如果你有任何其他问题或需要帮助,请随时告诉我。
英文:
- Can anyone help to solve this issue I can't get what wrong with code !!!!
答案1
得分: 1
.querySelector(".drum")选择第一个具有类名"drum"的元素,所以{i}是无用的,应该使用querySelectorAll。
英文:
.querySelector(".drum") selects the first element with class "drum" so the {i} is useless, use querySelectorAll.
答案2
得分: 0
正如在这篇帖子中提到的: https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors/285557#285557,你不应该上传代码的图像。当你在StackOverflow上提问题时,应该优先使用代码标记嵌入你的代码。这样,其他人可以更容易地回答你。
在你的情况下,你正在使用不良的JavaScript函数,如果你想选择所有具有"drum"类的按钮,应该使用querySelectorAll
来替代querySelector
。
querySelector
会选择并返回条件的第一个匹配项,正如文档中所述: https://developer.mozilla.org/fr/docs/Web/API/Document/querySelector。
英文:
As it mentioned in this post: <https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors/285557#285557>
, you should not upload image of your code. You should prefer embed your code with code tag when you ask question on stackoverflow.
In this way, people can answer you more easily.
In your case your using bad javascript function, you should use querySelectorAll
in place of querySelector
if you want to select all your button that have the drum
class.
querySelector
select and return the first match of the condition as it said in the documentation: <https://developer.mozilla.org/fr/docs/Web/API/Document/querySelector>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论