Javascript / DOM:如何删除DOM对象的所有事件?
只是提问:有没有办法彻底删除对象的所有事件,例如div?
编辑:我正在添加div.addEventListener('click',eventReturner(),false);一个事件。
function eventReturner() {
return function() {
dosomething();
};}EDIT2:我找到了一种方法,但是不能用于我的情况:
var returnedFunction;function addit() {
var div = document.getElementById('div');
returnedFunction = eventReturner();
div.addEventListener('click',returnedFunction,false); //You HAVE to take here a var and not the direct call to eventReturner(), because the function address must be the same, and it would change, if the function was called again.}function removeit() {
var div = document.getElementById('div');
div.removeEventListener('click',returnedFunction,false);}九州编程
茅侃侃
相关分类