addEventListener overwrites other event actions?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 01:13:07

问题


Does addEventListener overwrites previously defined actions for a particular event?For example,

<input type="text" name="ele" id="eleID" onfocus="doSomeThing();"/>

Now if I add another action for the same event,will both both function get executed?

eleID.addEventListener('focus',doSomethingElse,false);

If doSomethingElse() overwrites doSomeThing(), is there any other way to do it?


回答1:


No.

From MDC:

addEventListener is the way to register an event listener as specified in W3C DOM. Its benefits are as follows:

  • It allows adding more than a single handler for an event.

See example.




回答2:


No, it does not "overwrite" other handlers; that's why it's called "addEventListener". All the handlers are invoked when an event happens.

Now, I will say that mixing the old-style "DOM 0" event handler attachment mechanism (the "onevent" attributes) with event handlers added with "addEventListener()" is not a very good practice.



来源:https://stackoverflow.com/questions/6227667/addeventlistener-overwrites-other-event-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!