如何找出哪些JavaScript事件触发? [英] How to find out which JavaScript events fired?
问题描述
我有一个选择列表:
<select id="filter">
<option value="Open" selected="selected">Open</option>
<option value="Closed">Closed</option>
</select>
当我选择关闭
页面重新加载。在这种情况下,它会显示已关闭的门票(而不是打开的)。
When I select Closed
the page reloads. In this case it shows closed tickets (instead of opened). It works fine when I do it manually.
问题是当我选择关闭
时,该页面不会重新加载。 Watir :
The problem is that the page does not reload when I select Closed
with Watir:
browser.select_list(:id => "filter").select "Closed"
意味着某些JavaScript事件不会被触发。我可以用Watir触发事件:
That usually means that some JavaScript event is not fired. I can fire events with Watir:
browser.select_list(:id => "filter").fire_event "onclick"
但我需要知道要触发的事件。
but I need to know which event to fire.
有没有办法找出为元素定义哪些事件?
Is there a way to find out which events are defined for an element?
推荐答案
看起来像 Firebug (Firefox附加组件)有以下答案:
Looks like Firebug (Firefox add-on) has the answer:
- 打开Firebug
- 右键单击HTML选项卡中的元素
- 单击
日志事件
/ li>
- 启用控制台选项卡
- 单击控制台中的持久性标签(否则,控制台选项卡将在页面重新加载后清除)
- 选择
关闭
(手动) -
在控制台选项卡中将会出现如下所示:
- open Firebug
- right click the element in HTML tab
- click
Log Events
- enable Console tab
- click Persist in Console tab (otherwise Console tab will clear after the page is reloaded)
- select
Closed
(manually) there will be something like this in Console tab:
...
mousemove clientX=1097, clientY=292
popupshowing
mousedown clientX=1097, clientY=292
focus
mouseup clientX=1097, clientY=292
click clientX=1097, clientY=292
mousemove clientX=1096, clientY=293
...
资料来源: Firebug提示:日志事件
这篇关于如何找出哪些JavaScript事件触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!