JQuery会否覆盖现有的内联事件处理程序? [英] Will JQuery override existing inline event handlers?
问题描述
我正在监控用户活动 - 就像用户点击或按键时一样。
这只是为了看看用户是否空闲。
为此,我正在钻取所有的iframe,其div标签和注册鼠标悬停和点击事件。
同时我不想覆盖/破坏应用程序定义的现有内联事件处理程序。
将jquery覆盖现有的事件处理程序?如果是的话,请问这样做是为了确保我不这样做吗?
这是我的使用。
$(divElementObj).click(function(){
alert(div click);
});
不,jQuery通过使用 addEventListener
/ 。内联和预先存在的处理程序不会被覆盖。
请参阅jsFiddle示例和 jQuery源来显示如何做到这一点。
I have a site which is built out of many iframes. I am working on monitoring user activity - like when user clicks or keydown.
This is only to see if user is idle or not.
For this, I am drilling down to all iframes,its div tags and registering hover and click events. Meanwhile I dont want to override/break existing inline event handlers which are defined by the application.
Will jquery override exiting eventhandlers? If yes, how can check this to make sure I dont do this?
Here is my usage.
$(divElementObj).click( function() {
alert("div click");
});
No, jQuery works by using addEventListener
/attachEvent
. Inline and pre-existing handlers are not overwritten.
See jsFiddle example and the jQuery source to show how this is done.
这篇关于JQuery会否覆盖现有的内联事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!