如何在React Input Onkeydown事件中获得默认行为?
我在捕获键盘事件的地方有一个输入元素。
onKeyDown={(e) => {
if (e.key === "ArrowDown") {
console.log("pressed down arrow");
} else if (e.key === "ArrowUp") {
console.log("pressed up arrow");
} else if (e.key === "Enter") {
console.log("pressed enter");
} else {
how do I get default behavior for the rest of the keys?
Ex: backspace
When backspace is pressed, it is not deleting the characters from the input box
}
}}
这是沙盒 link
I have an input element in where I am capturing keyboard events.
onKeyDown={(e) => {
if (e.key === "ArrowDown") {
console.log("pressed down arrow");
} else if (e.key === "ArrowUp") {
console.log("pressed up arrow");
} else if (e.key === "Enter") {
console.log("pressed enter");
} else {
how do I get default behavior for the rest of the keys?
Ex: backspace
When backspace is pressed, it is not deleting the characters from the input box
}
}}
Here is the sandbox link for the same
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论