听取按键在Quill.js中输入 [英] Listen to key press Enter in Quill.js

查看:383
本文介绍了听取按键在Quill.js中输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,Quill可以处理Enter键,但我无法使其正常工作。

According to the documentation, Quill can handle the Enter key but I can't make it work.

我已按照其网站上列出的这些步骤进行操作:

I have followed these steps listed on their site:


  1. 导入键盘模块: const Keyboard = Quill.import('modules / keyboard'); Quill.js扩展程序导入文档。

  2. 添加名为键绑定的自定义事件。 Quill.js密钥绑定文档

  3. 致电a处理事件的功能。

  1. Import Keyboard module: const Keyboard = Quill.import('modules/keyboard'); Quill.js Extension import documentation.
  2. Add the custom event called key binding. Quill.js Key binding documentation
  3. Call a function to handle the event.

我的代码如下:

quill.keyboard.addBinding({
key:Keyboard.keys.ENTER,
handler:function(range,context){
console.log('Enter Key !!!');
result.innerText ='Key presset = ENTER';
}
})

代码示例

我在MacOS High Sierra 10.13.3上尝试过Chrome(最新版本)和Safari 11.0.3

I have tried on Chrome (latest version) and Safari 11.0.3 on MacOS High Sierra 10.13.3

推荐答案

不确定您是否需要Enter键或Space键,但是您在右侧页面上的键盘模块 b错过了这个关键句:

Not sure if you want the Enter key or the Space key but you were on the right page with the Keyboard module but missed this key sentence:


是JavaScript事件键码,但字母数字键和一些常用键允许使用字符串短字。

The key is the JavaScript event key code, but string shorthands are allowed for alphanumeric keys and some common keys.

所以你可以指定13或'enter'如果你的意思是输入密钥或32,如果你的意思是空格键(遗憾的是没有空格键的快捷方式)。

So you can either specify 13 or 'enter' if you meant the Enter key or 32 if you meant the Space key (sadly there is no shortcut for the Space key).

即将推出的2.0版本(没有公共时间表)也将支持新的更容易使用 KeyboardEvent.key 但目前你应该使用 keyCode

The upcoming 2.0 version (no public timeline) will also support the new easier to use KeyboardEvent.key but currently you should use keyCode.

这篇关于听取按键在Quill.js中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆