如何找出触发了哪些 JavaScript 事件? [英] How to find out which JavaScript events fired?

查看:30
本文介绍了如何找出触发了哪些 JavaScript 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择列表:

<select id="filter">
  <option value="Open" selected="selected">Open</option>
  <option value="Closed">Closed</option>
</select>

当我选择 Closed 时,页面会重新加载.在这种情况下,它显示已关闭的票证(而不是已打开的票证).当我手动执行时,它工作正常.

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 选择 Closed 时页面不会重新加载:

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:

  • 打开萤火虫
  • 右键单击 HTML 标签中的元素
  • 点击Log Events
  • 启用控制台选项卡
  • 点击在控制台选项卡中保留(否则控制台选项卡将在页面重新加载后清除)
  • 选择 Closed(手动)
  • 控制台选项卡中会有类似的内容:

  • 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屋!

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