如何在Firefox上的html表上触发onkeydown事件? [英] How can I trigger an onkeydown event on html table on Firefox?

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

问题描述

我想捕获表格单元格上的击键。
我有以下代码在IE上工作但在Firefox / Chrome上没有。

I want to capture the keystrokes on a table's cells. I have the following code that is working on IE but not on Firefox/Chrome.

<table id="testing" onkeydown="alert('testing')"><br />
    <tr><td>testing</td></tr>` <br />
    </table>
<br />

有什么建议吗?

推荐答案

http://www.w3schools.com/jsref/jsref_onkeydown.asp 指定大多数标签支持onkeydown。

http://www.w3schools.com/jsref/jsref_onkeydown.asp specifies that most of the tags support onkeydown.

您需要设置 tabindex 属性(例如 tabindex =1)到某个值,因此它可以识别该表是键盘可选的。这允许触发键盘事件。以下内容适用于firefox:

You need to set tabindex property (eg tabindex="1") to some value, so it can identify that this table is keyboard selectable. That allows the keyboard event to be triggered. Following will work in firefox:

<table id="testing" onkeydown="alert('testing')" tabindex="0"><br />
<tr><td>testing</td></tr><br />
</table> 

这篇关于如何在Firefox上的html表上触发onkeydown事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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