只是一个问题:有什么办法可以完全删除某个对象(例如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);
}