“.AddeventListener ()” Respostas de código

ouvinte de evento JavaScript OnClick

document.getElementById("myBtn").addEventListener("click", function() {
  alert("Hello World!");
});
Batman

JavaScript AddEventListener

var element = document.getElementById("#id");
element.addEventListener('click', function(){
	console.log("click");
});
Innocent Ibis

JS addEventListener

var element=document.getElementById("some_id");
var listener=element.addEventListener('click',function(event){                          
            
 }); 
Grepper

addEventListener JavaScript

// The anwer of Innocent Ibis is wrong!!
// It should not have a # for the ID seens we are using getElementById
var element = document.getElementById("id");
element.addEventListener('click', function(){
	console.log("click");
});
Karamolegkos

.AddeventListener ()

eventTarget.addEventListener("event", eventHandlerFunction);
Douglas Stemple

Procure respostas de código populares por idioma

Procurar outros idiomas de código