JQuery会否覆盖现有的内联事件处理程序? [英] Will JQuery override existing inline event handlers?

查看:104
本文介绍了JQuery会否覆盖现有的内联事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站是由许多iframe构建的。
我正在监控用户活动 - 就像用户点击或按键时一样。



这只是为了看看用户是否空闲。



为此,我正在钻取所有的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆