Javascript removeEventListener not working

2019-01-03 06:26发布

I have the following code to add eventListener

 area.addEventListener('click',function(event) {
              app.addSpot(event.clientX,event.clientY);
              app.addFlag = 1;
          },true);

It is working correctly as expected..Later in another function i tried to remove the event listener using the following code

 area.removeEventListener('click',function(event) {
              app.addSpot(event.clientX,event.clientY);
              app.addFlag = 1;
          },true);

But the even listener is not removed..Why is it happening?Is there any problem with my removeEventListener()? Note:Here area is something like document.getElementById('myId')

7条回答
beautiful°
2楼-- · 2019-01-03 07:21

define your Event Handler first,

and then

area.addEventListener('click',handler);
area.removeEventListener('click',handler);
查看更多
登录 后发表回答