如何在单击按钮时触发 Quill JS 的提及模块

  • 本文关键字:JS Quill 模块 单击 按钮 quill
  • 更新时间 :
  • 英文 :


我正在为我的quill编辑器使用这个quill提及模块:https://github.com/afry/quill-mention.

我的编辑器工具栏上有一个"@"按钮,我希望如果我点击会出现提及列表。

我想我的代码会是这样的:

$("button.mention-btn").on("click", triggerMention);
function triggerMention(){
if(!quill.hasFocus()){
quill.focus();
}
evt1 = $.Event('keydown');
evt1.which = 16; // shift
evt2 = $.Event('keypress');
evt2.which = 50; // 2
quill.trigger(evt1);
quil.trgger(evt2);
}

有quill js经验的人能帮忙吗。提前谢谢。

如文档中所述,方法openMenu(denotationChar):

打开给定指称字符的提及菜单。

为了调用此方法,我们需要从Quill中检索模块,如:quill.getModule('mention')

以下代码应该有效:

function showMenu() {
quillEditor.getModule("mention").openMenu("@");
}

代码笔:https://codepen.io/andreivictor/pen/yLbjPaQ