找出点击时触发的 javascript 函数...
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11097825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find out which javascript function is fired on click...
提问by Dee
Is there a way to find out which javascript function is fired by click on a certain button?
有没有办法通过单击某个按钮来找出哪个 javascript 函数被触发?
Let me explain ... I have a web page with a large js script (not made ??by me), I've to detect which function is triggered by a specific button, I need to find the function triggered by this btn.
让我解释一下......我有一个带有大型js脚本的网页(不是我制作的),我必须检测哪个功能是由特定按钮触发的,我需要找到由这个btn触发的功能。
回答by alex
Use Chrome's Web Inspector to inspect the element and check out the Event Listenerspanel.
使用 Chrome 的 Web Inspector 检查元素并查看Event Listeners面板。
If the code attaching the event is in a library (for example, by Zepto in my example), set a breakpoint on the line and examine the call stack to see where it originated in your code.
如果附加事件的代码在库中(例如,在我的示例中由 Zepto 提供),请在该行上设置一个断点并检查调用堆栈以查看它在代码中的位置。
As you can see, the event has originated in my code and now I know the filename and line number.
如您所见,该事件起源于我的代码,现在我知道文件名和行号。
回答by Sarfraz
Inside your functions, you can put arguments.callee
to know about it. Notice that this is deprecatedbut should tell you what you are looking for.
在您的函数中,您可以arguments.callee
了解它。请注意,这已被弃用,但应该告诉您您在寻找什么。
alert(arguments.callee);
回答by naveen
Why don't you use Stack Trace for JavaScript, ie, stacktrace.js
为什么不使用Stack Trace for JavaScript,即 stacktrace.js
Go to the above link, click on Bookmarkletand load the js file on any site you wish to inspect.
转到上面的链接,单击Bookmarklet并在您要检查的任何站点上加载 js 文件。