首页 > 解决方案 > Android 上的 Chrome 按键事件报告很有趣

问题描述

我在带有输入框的 Android (86.0.4240.99) 上使用 Chrome 时遇到问题。基本上,我正在听 keydown 事件并操作文本框,所以感觉更像是一个计算器条目/应用输入掩码,因为他们用逗号等键入。

对于我的输入:

type="text"
pattern="[0-9]*"
inputmode="decimal"

在按下“.”时的 keydown 事件中,事件对象很奇怪,键为“未识别”,键码为 229(逗号的作用完全相同)。这些数字似乎工作正常,只是键盘上出现的“,”,“。”和“-”按钮可以做到这一点。通过我手动操作输入的方式,我需要知道小数点何时被点击,但我无法区分。

这是 KeboardEvent 对象:

{ altKey: false
bubbles: true
cancelBubble: false
cancelable: true
charCode: 0
code: ""
composed: true
ctrlKey: false
currentTarget: null
defaultPrevented: true
detail: 0
eventPhase: 0
isComposing: false
isTrusted: true
key: "Unidentified"
keyCode: 229
location: 0
metaKey: false
path: (22) [input#input-518, div.v-text-field__slot, div.v-input__slot, div.v-input__control, div.v-input.v-input--is-label-active.v-input--is-dirty.v-input--is-focused.theme--light.v-text-fiel…, div.col, div.row, div, div.container, div.v-window-item.v-window-item--active, div.v-window__container, div.v-window.v-item-group.theme--light.v-tabs-items, div.v-tabs.v-tabs--grow.theme--light, div.v-card__text, div#tasks.v-card.v-sheet.theme--light, div.v-dialog.v-dialog--active.v-dialog--persistent, div.v-dialog__content.v-dialog__content--active, div#app.v-application.v-application--is-ltr.theme--light, body, html.overflow-y-hidden, document, Window]
repeat: false
returnValue: false
shiftKey: false
sourceCapabilities: InputDeviceCapabilities {firesTouchEvents: false}
srcElement: input#input-518
target: input#input-518
timeStamp: 489740.7000000003
type: "keydown"
view: Window {window: Window, self: Window, document: document, name: "", location: Location, …}
which: 229
}

有没有人遇到过这个或知道如何解决它?它是 chrome for android 中的错误吗?它在 Chrome for windows 和 iOS 上都能完美运行。

标签: javascriptandroidhtmlgoogle-chrome

解决方案


推荐阅读