Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

javascript - 测试事件处理程序是否绑定到jQuery中的元素[重复](test if event handler is bound to an element in jQuery [duplicate])

This question already has an answer here:(这个问题在这里已有答案:)

jQuery find events handlers registered with an object 14 answers(jQuery查找用对象 14回答 注册的事件处理程序)

Is it possible to determine whether an element has a click handler, or a change handler, or any kind of event handler bound to it using jQuery?(是否可以确定元素是否具有单击处理程序,或更改处理程序,或使用jQuery绑定到它的任何类型的事件处理程序?)

Furthermore, is it possible to determine how many click handlers (or whatever kind of event handlers) it has for a given type of event, and what functions are in the event handlers?(此外,是否可以确定它对于给定类型的事件有多少点击处理程序(或任何类型的事件处理程序),以及事件处理程序中有哪些功能?)   ask by Elias Zamaria translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can get this information from the data cache.(您可以从数据缓存中获取此信息。)

For example, log them to the console (firebug, ie8):(例如,将它们记录到控制台(firebug,ie8):) console.dir( $('#someElementId').data('events') ); or iterate them:(或者迭代它们:) jQuery.each($('#someElementId').data('events'), function(i, event){ jQuery.each(event, function(i, handler){ console.log( handler.toString() ); }); }); Another way is you can use the following bookmarklet but obviously this does not help at runtime.(另一种方法是你可以使用下面的书签,但显然这在运行时没有帮助。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...