[英]I have been adding an event Listener to this button and getting an error. What I'm I doing wrong?
[英]How do I assign different handler to one event listener like the click addEventListener. This is what I have being doing
Var a = document.querySelectorAll("img")
For(i = 0; i < a.length; i++) {
Var b = a[i].addEventListener ("click", tee, bee);
Function tee () {
Console.log("Hello")
}
Function bee () {
Console.log("world")
}
首先是 JavaScript 中的案例。 addEventListener
接受單個偵聽器。
你可以調用function里面的第二個function:
var a=document.querySelectorAll("img") for(i=0; i<a.length; i++){ var b = a[i].addEventListener("click", tee); } function tee (){ console.log("Hello") bee(); } function bee (){ console.log("world") }
<img alt="111"/> <img alt="222"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.