键盘快捷键 JQUERY - Command+S、Control+S
我的网站上有一个文本编辑器,我希望用户能够使用键盘快捷键进行保存,就像在 Microsoft Word 中一样:
- 对于 Mac:Cmd+S
- 对于 PC:Ctrl+S
在 jQuery 中实现此目的的最佳方法是什么?另外,这将用于在 CKEditor 中保存内容,CKEditor 使用 iFrame,不确定这是否是一个问题。
I have a text editor on my site and I want users to be able to use keyboard shortcuts to save, just like they would in Microsoft Word:
- For the Mac: Cmd+S
- For the PC: Ctrl+S
What is the best way to accomplish this in jQuery? Also, this will be used to save content in CKEditor, which uses an iFrame, not sure if that's an issue or not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您知道 CKEditor 有内置热键功能吗?
实现起来非常简单:您在配置数组中设置一个数组
keylines
;从上面的链接获取示例数组;查找“S”的击键;并通过条目和适当的 CKEditor 命令修改数组。我现在无法测试它,但这就是它应该的样子。您可能需要查找适合您要执行的“保存”操作的命令。You are aware that CKEditor has built in hotkey functionality?
It's pretty straightforward to implement: You set up an array
keystrokes
in your config array; take the example array from the link above; Look up the keystroke for "S"; and amend the array by an entry for it, and the appropriate CKEditor command. I can't test it right now but this is what it should look like. You may need to look up the appropriate command for the "save" operation you want to execute.在 Mac 上,要捕获 CMD-s,请将事件处理程序分配给编辑器,如下所示:
在我的示例中,我正在调用
save()
函数。On the Mac, to capture CMD-s, assign an event handler to the editor like this:
In my example, I'm calling my
save()
function.