当我点击网页中的一个元素时,如何监控Javascript被触发? [英] How do I monitor what Javascript is being triggered when I click an element in a webpage?

查看:158
本文介绍了当我点击网页中的一个元素时,如何监控Javascript被触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用另一个开发人员的代码:当我点击他的页面上的一个元素并且JavaScript / jQuery事件被触发时,我该如何监视被触发的JS?我有点熟悉事件侦听,但我的印象是,您必须知道要声明的变量或正在执行的代码行。我不知道,因为我试图找到它在他的来源为了添加额外的功能和重构它。谢谢。



示例:他有一个手风琴弹出窗口,当您点击加号后再显示更多的文字,然后再隐藏它。我想改进它,以便加号通过添加一行修改CSS背景图像的JS来改变为负号。我只是不知道他嵌入了他的功能。



编辑:感兴趣的方法涉及调试工具的Web浏览器或涉及代码的编程解决方案。我假设解决方案将涉及一个调试工具,因为我不知道在这个大型应用程序中找到以前开发人员的JS代码。

解决方案

按F12或右键点击网页,然后选择inspect元素(不必是要检查的元素)。



然后可以使用几个工具:



1)时间轴标签和记录按钮,将显示所有发生的事件



那么当您使用上述



确定过程时,请转到



2)源选项卡和子选项内容脚本并搜索您感兴趣的函数或变量或脚本文件(使用ctrl + F在脚本文件中搜索,因为它大大节省了时间)



PS



使用chrome


Working with another developer's code: When I click an element on his page and a Javascript/jQuery event is triggered, how do I monitor what JS is being triggered? I am somewhat familiar with event listening but I was under the impression that you must either know the variable being declared or a line of code that is being executed. I don't know either as I am trying to find it within his source in order to add additional functionality and refactor it. Thank you.

Example: He has an "accordion flyout" which reveals more text when you click on a plus symbol and then hides it when you click it again. I want to improve it so that the plus symbol changes to a minus symbol by adding a line of JS that modifies the CSS background-image. I just don't know where he has embedded his functionality.

EDIT: Interested in either a method involving debugging tools for web browser OR a programmatic solution involving code. I'm assuming the solution will involve a debugging tool as I don't know where to find previous developer's JS code in this large application.

解决方案

Press F12 or right click on the webpage and choose inspect element ( doesn't have to be the element you're checking).

Then you can use several tools:

1) Timeline tab and the recording button which will show all the events that are happening

then when you have identified the process using the above

go to

2) Sources tab and subtab Content Scripts and search for the function or variable or script file you're interested in ( use ctrl + F to search in script files as it greatly saves time)

P.S.

Using chrome

这篇关于当我点击网页中的一个元素时,如何监控Javascript被触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆