“JavaScript menghapus pendengar acara” Kode Jawaban

JavaScript Hapus semua pendengar acara

That is not possible without intercepting addEventListener calls and keep track of the listeners or use a library that allows such features unfortunately. It would have been if the listeners collection was accessible but the feature wasn't implemented.

The closest thing you can do is to remove all listeners by cloning the element, which will not clone the listeners collection.

Note: This will also remove listeners on element's children.

var el = document.getElementById('el-id'),
    elClone = el.cloneNode(true);

el.parentNode.replaceChild(elClone, el);
Delta Sierra

JavaScript menghapus pendengar acara

var someEventHander=function(event){
	console.log("do something");
}

//add listener
document.getElementById("someid").addEventListener('click',someEventHander);

//remove listener 
document.getElementById("someid").removeEventListener('click',someEventHander);
Grepper

.RemoveEventListener ()

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

Referensi acara pendengar acara untuk dihapus

element.addEventListener('click',element.fn=function fn() {
    //  Event Code
}, false);
element.removeEventListener('click',element.fn, false);
Better Beaver

JavaScript menghapus pendengar acara tidak berfungsi

var someEventHander=function(){
	console.log("do something");
}
var handlerCopy=someEventHandler.bind(var1,var2)
//add listener
document.getElementById("someid").addEventListener('click',handlerCopy,true);
//remove listener 
document.getElementById("someid").removeEventListener('click',handlerCopy,true);
Grepper

Jawaban yang mirip dengan “JavaScript menghapus pendengar acara”

Pertanyaan yang mirip dengan “JavaScript menghapus pendengar acara”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya