【发布时间】:2014-03-06 16:47:16
【问题描述】:
我知道这个问题在 stackoverflow 上被问过几次,我尝试了一些不同的解决方案,但找不到适合我的代码。
我想在 Mac 上捕获键盘命令 Ctrl+S 和 Command+S,目前我使用此代码(使用 jQuery 2.1.0):
jQuery(window).on('keypress', function(event){
if (!(event.which == 115 && (event.ctrlKey||event.metaKey)) && !(event.which == 19)) return true;
// my save function
event.preventDefault();
return false;
});
此代码适用于:
- Safari:使用 Ctrl+S 和 Command+S
- Firefox:使用 Ctrl+S 和 Command+S
- Chrome:仅 Ctrl+S有效
你会看到问题是谷歌浏览器,这里我只能捕获Ctrl+S。
有人知道我该如何解决这个问题吗?
【问题讨论】:
标签: jquery macos google-chrome keyboard-shortcuts keypress