Chrome Dev Tools: Tells me what type of event is attached to element but which file?

巧了我就是萌 提交于 2020-01-02 04:51:12

问题


In Chrome when I right click on a DOM element to see which event listeners are attached it always says jquery.min.js:2 . However, I would like to know which of my JavaScript files contains that listener (e.g. click event listener).

For example, which file has this code in it?

$('#clickMe').on('click', function(e){ //clicked});


回答1:


Chrome has no way of knowing that.

When you write $(...).click(function), the event handler that gets added to the function is always within jQuery.
Chrome cannot know what callback the jQuery event handler will eventually run.




回答2:


If you use addEventListener (instead of $(...).click() ) then Chrome Dev Tools will show you the line in your file where that handler was added.



来源:https://stackoverflow.com/questions/14881737/chrome-dev-tools-tells-me-what-type-of-event-is-attached-to-element-but-which-f

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