更新时间:2023-12-05 22:28:34
有没有任何其他addEventListener()方法我可以替换keyup?
with no success. Is there any other addEventListener() method I can replace keyup with?
是的,模糊
如果您要添加keydown < div>
元素上的事件,您可以执行以下操作:
If you would like to add keydown events on a <div>
element, you can do the following:
首先, tabindex属性:
First, you need to set the tabindex attribute:
<div id="a-div" tabindex="1" />
然后,
(2)绑定到键:
Then, (2) Bind to keydown:
$('#mydiv').bind('keydown', function(event) {
//console.log(event.keyCode);
});
如果你希望你的div从一开始就是专注:
If you would like your div to be "focused" from the start:
$(function() {
$('#mydiv').focus();
});