如何发现是否对元素执行了attachEvent [英] How to discover if attachEvent was done to an element

查看:66
本文介绍了如何发现是否对元素执行了attachEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我需要检查是否对一个元素进行了attachEvent。问题是

,attachEvent不会将此信息保存在任何地方。有没有

任何

这样做的方式???

谢谢,

Max

解决方案

8月28日下午4:37,Max< krya ... @ yahoo.comwrote:


大家好,


我需要检查是否对一个元素进行了attachEvent。问题是

,attachEvent不会将此信息保存在任何地方。有没有

任何

这样做的方式???


谢谢,

最高



当使用* attachEvent时,是否需要准确通知*?或者你稍后再来看看
并检查元素以查看它是否在过去的某个时刻附加了

事件监听器?

另外,由于其他原因,我并不特别关心使用IE的

专有attachEvent。虽然有些人会掏空我说这个,但是试试这个,请尝试使用YAHOO!用于包装浏览器差异的UI库(http://

developer.yahoo.com/yui/)。你的生活

将更容易:YAHOO公开YAHOO.util.Event.getListeners,一个

方法,返回所有(YAHOO-library)附加的侦听器

元素。


-David


Max写道:


我需要检查是否对元素执行了attachEvent。问题是

,attachEvent不会将此信息保存在任何地方。有没有

任何方式来做这个???



(你的问号键是borken。)


我什么都不知道。但是,由于attachEvent()是IE专有的,你可以

同样使用`onclick''属性,你可以测试它的值。

你的代码仍然是专有,但至少会支持更多的DOM

(包括NN4,Geckos,Opera,以及可能是KHTML和WebKit)。我想知道为什么你认为你需要它的原因。

有没有人知道确定DOM对象是否有事件的方法

监听器使用Element :: addEventListener()添加到它,或者是否可以

返回添加的监听器列表,如果是,如何?

PointedEars

-

Prototype.js是由不懂人javascript的人写的

谁也不知道JavaScript的。不知道javascript的人不是设计使用javascript的系统的最佳建议来源。

- Richard Cornford,cljs,< f8 ** *****************@news.demon.co.uk>


David Golightly写道:
< blockquote class =post_quotes>
另外,由于其他原因,我并不特别在意使用IE的

专有的attachEvent。虽然有些人会掏空我说这个,但是试试这个,请尝试使用YAHOO!用于包装浏览器差异的UI库(http://

developer.yahoo.com/yui/)。你的生活

将更容易:YAHOO公开YAHOO.util.Event.getListeners,一个

方法,返回所有(YAHOO-library)附加的侦听器

元素。



仅仅处理以前注册的事件几乎不能成为使用垃圾代码的


PointedEars

-

var bugRiddenCrashPronePieceOfJunk =(

navigator.userAgent.indexOf(''MSIE 5'')!= -1

&& navigator.userAgent.indexOf(''Mac'')!= -1

)// Plone,register_function.js:16


Hi All,

I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any
way to do this???
Thanks,
Max

解决方案

On Aug 28, 4:37 pm, Max <krya...@yahoo.comwrote:

Hi All,

I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any
way to do this???

Thanks,
Max

Do you need to be notified exactly *when* attachEvent was used? Or do
you come along later and inspect the element to see if it had had an
event listener attached at some point in the past?

Also, for this an other reasons, I don''t particularly care to use IE''s
proprietary attachEvent at all. Though some would eviscerate me for
saying this, try using the YAHOO! UI library (http://
developer.yahoo.com/yui/) to wrap the browser differences. Your life
will be MUCH easier: YAHOO exposes YAHOO.util.Event.getListeners, a
method that returns all (YAHOO-library) attached listeners on an
element.

-David


Max wrote:

I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any way to do this???

(Your Question Mark key is borken.)

I don''t know any. But, since attachEvent() is IE-proprietary, you could
equally use the `onclick'' property, which value you can test against.
Your code would still be proprietary, but would at least support more DOMs
(including NN4, Geckos, Opera, and presumably KHTML and WebKit). I wonder
why you think you need that, though.

Does anyone know a way to determine whether a DOM object has an event
listener added to it with Element::addEventListener(), or if it is possible
to return a list of the added listeners, and if yes, how?
PointedEars
--
Prototype.js was written by people who don''t know javascript for people
who don''t know javascript. People who don''t know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>


David Golightly wrote:

Also, for this an other reasons, I don''t particularly care to use IE''s
proprietary attachEvent at all. Though some would eviscerate me for
saying this, try using the YAHOO! UI library (http://
developer.yahoo.com/yui/) to wrap the browser differences. Your life
will be MUCH easier: YAHOO exposes YAHOO.util.Event.getListeners, a
method that returns all (YAHOO-library) attached listeners on an
element.

Mere handling of previously registered events is hardly a justification
for using junk code.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf(''MSIE 5'') != -1
&& navigator.userAgent.indexOf(''Mac'') != -1
) // Plone, register_function.js:16


这篇关于如何发现是否对元素执行了attachEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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