javascript 为您的 HTML5 应用程序创建键盘快捷键?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15213912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:53:39  来源:igfitidea点击:

Creating keyboard shortcuts for your HTML5 app?

javascriptjqueryhtmleventskeyboard-shortcuts

提问by MaiaVictor

How to create keyboard shortcuts for HTML5 apps? Using key events don't work because some browsers already define most of those inputs for built-in features such as Save As..., (which are useless for interactive apps).

如何为 HTML5 应用程序创建键盘快捷键?使用按键事件不起作用,因为某些浏览器已经为内置功能定义了大部分输入,例如另存为...(对于交互式应用程序无用)。

回答by apoq

Well, that one works for me: (CTRL-S in Chrome)

嗯,那个对我有用:(Chrome 中的 CTRL-S)

$(document).keydown(function(evt){
    if (evt.keyCode==83 && (evt.ctrlKey)){
        evt.preventDefault();
        alert('worked');
    }
});

回答by wildcards

try giving this a look.

试试看。

http://www.openjs.com/scripts/events/keyboard_shortcuts/#add_docs

http://www.openjs.com/scripts/events/keyboard_shortcuts/#add_docs

sample to add shortcut

添加快捷方式的示例

shortcut.add("Ctrl+B",function() {
alert("Bold");});

sample to remove shortcut

删除快捷方式的示例

shortcut.remove("Ctrl+B");