How to find out what's preventing a click from happening?

时间:2018-04-20 21:28:03

标签: javascript html

I have the following link on the page:

<a href="/go/some/where.htm">...</a>

It lives among HTML that makes up a google.maps.InfoWindow box (which itself doesn't have a click event). This infobox comes up when the user moves the mouse over a mapping pin. For whatever reason, when the user clicks on a link in the infobox, it doesn't fire and I am trying to find out why.

The code base is huge and I have no idea where exactly the preventDefault or propagation is stopped. Is there an easier way? Can I hook into the event flow some way that would show me what is preventing the click?

3 个答案:

答案 0 :(得分:6)

除了Wyatt提到的JavaScript调试器之外,您还可以在Chrome Developer Tools中的任何DOM元素上查看事件监听器。右键单击元素&gt;检查:选择右侧的“事件监听器”选项卡。

enter image description here

答案 1 :(得分:2)

我之前遇到过类似的情况,你有几个选择。

  1. 只需搜索所有代码preventDefault或类似代码的所有文字,然后查看每个代码的内容
  2. 如果您使用的是Chrome等现代网络浏览器,则可以step through your code.

答案 2 :(得分:1)

在Firefox中,您可以右键单击元素,选择Inspect,然后单击元素源代码末尾的灰色迷你按钮,查看绑定事件列表。 然后单击该事件(此处:&#34;单击&#34;)以查看自动美化的代码。

Visual explanation