Javascript - 如何创建按键事件? [英] Javascript - How to create a keypress event?
本文介绍了Javascript - 如何创建按键事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在互联网上查看过这个,我能找到的都是折旧的函数,所以在发布之前请检查以确保您建议的代码没有折旧.
I've looked on the internet for this and all I can find are depreciated functions so before posting please check to make sure that the code you suggest isn't depreciated.
我已经找到并尝试了:https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent
$(document).ready(function () {
var x = new KeyboardEvent("FormatCode", deprectiatedArgument);
});
但经过进一步检查,KeyboardEventInit
已贬值.
But after further inspection the KeyboardEventInit
is depreciated.
我想在按下 CTRL + K 键时创建一个事件.
I would like to create an event on pres of the CTRL + K keys.
推荐答案
键盘上的每个按钮都有一个特定的键码.他们都在这里http://keycode.info/.
You have a specific key code for every button on the keyboard. All of them are here http://keycode.info/.
$(document).keyup(function(e) {
if (e.keyCode === 13) function(); // enter
if (e.keyCode === 27) function(); // esc
});
这篇关于Javascript - 如何创建按键事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文