简体   繁体   English

找到在Web浏览器中触发然后事件的jQuery代码

[英]Find jQuery code that trigger then event in Web Browser

I joined a team to work on a project. 我加入了一个团队来完成一个项目。 Now that they use jQuery and a lot of the javascript file are external files instead of embedded. 现在他们使用jQuery和许多javascript文件是外部文件而不是嵌入式。

When I clicked a button, which simply looks like: 当我点击一个按钮时,它看起来像:

<a class="button_cancel">Cancel</a>

It trigger an event which is defined in one javascript file. 它触发一个javascript文件中定义的事件。

Is there a way to locate the file (or even the exact line of the file) when the onclick is triggered? 有没有办法在触发onclick时找到文件(甚至文件的确切行)?

You could use some developer tools like the Firebug extension for Firefox (which I hope you already have). 您可以使用一些开发人员工具,如Firefox的Firebug扩展(我希望您已经拥有)。 In Firebug's "Script" panel you can set "Break on next" (in the top left corner) which practically means, set a breakpoint in whichever line is executed next. 在Firebug的“脚本”面板中,您可以设置“Break on next”(在左上角),这实际上意味着,在接下来执行的任何一行中设置一个断点。 Activate that. 激活它。 Then click the button. 然后单击按钮。 You should land in the executed file. 你应该登陆执行的文件。 If not step through the code a bit and you will get there. 如果没有逐步完成代码,你就会到达那里。 The only annoying thing would be if there is some other JavaScript that is continuously running. 唯一令人讨厌的事情是,如果有其他JavaScript持续运行。

I believe the developer tools of Chrome, Safari and Opera provide similar features. 我相信Chrome,Safari和Opera的开发者工具提供了类似的功能。

EDIT: Chrome has it too. 编辑: Chrome也有它。 Panel "Sources" in the top right, and it's called "Pause Script Execution". 面板“Sources”位于右上角,它被称为“Pause Script Execution”。

Visual Event 2 can provide you with this informations in a nice and easy to use way. Visual Event 2可以以一种简单易用的方式为您提供此信息。

Visual Event is an open source Javascript bookmarklet which provides debugging information about events that have been attached to DOM elements. Visual Event是一个开源的Javascript书签,它提供有关已附加到DOM元素的事件的调试信息。 Visual Event shows: 视觉事件显示:

  • Which elements have events attached to them 哪些元素附加了事件
  • The type of events attached to an element 附加到元素的事件类型
  • The code that will be run with the event is triggered 将触发将与事件一起运行的代码
  • The source file and line number for where the attached function was defined (Webkit browsers and Opera only) 附加函数定义位置的源文件和行号(仅限Webkit浏览器和Opera)

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM