gpt4 book ai didi

javascript - 虚拟键盘事件

转载 作者:行者123 更新时间:2023-11-29 14:42:31 25 4
gpt4 key购买 nike

这里有没有人遇到过当是虚拟键盘且按键不是数字时不触发键盘事件的问题。在 Android 6.0.1 上运行的 Nexus 7 平板电脑会出现此问题。

$('.some.selector').on('keypress', function () {
console.log('Pressed');
})

以上代码在以下情况下触发:单击的键是一个数字,如 0-9,如果使用其他设备,如 iPad 或 iPhone,或者如果我从 PC 远程调试我的平板电脑,那么我可以从键盘按下物理键。我在平板电脑上使用 Chrome 49 浏览器。

最佳答案

https://developer.mozilla.org/en-US/docs/Web/Events/keypress

keypress 事件已弃用,

Chrome does not fire the keypress event for known keyboard shortcuts (reference). Which keyboard shortcuts are known depends on the user's system. Use the keydown event to implement keyboard shortcuts.

尝试使用 input 或 `keydown/keyup' 事件来代替。

https://developer.mozilla.org/en-US/docs/Web/Events/input

https://developer.mozilla.org/en-US/docs/Web/Events/keydown

https://developer.mozilla.org/en-US/docs/Web/Events/keyup

注意!

The DOM input event is fired synchronously when the value of an < input> or < textarea> element is changed. Additionally, it fires on contenteditable editors when its contents are changed. In this case, the event target is the editing host element. If there are two or more elements which have contenteditable as true, "editing host" is the nearest ancestor element whose parent isn't editable. Similarly, it's also fired on root element of designMode editors.

关于javascript - 虚拟键盘事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36862353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com