Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 DOM 事件等不是很熟悉。目前,当用户在键盘和/或键盘上按下 1 时,我想做的是单击第一个对象,这是一个类名为“test”的 HTML 链接。我会使用 keydown 事件,因为它似乎比按键更受支持。我该怎么做呢?
以 jquery 为例:
$(document).on('keydown', function(event) { if(event.keyCode == 49 // press key 1 on keyboard || event.keyCode == 97) // press key 1 on keypad location.href = $('a.test').attr('href'); });
jsFiddle