问题
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