简体   繁体   English

从 HTML 元素获取 Quill 编辑器实例

[英]Get Quill editor instance from HTML element

Assuming I created an editor instance for a certain element, eg via const editor = new Quill('#editor', {...some options});假设我为某个元素创建了一个编辑器实例,例如通过const editor = new Quill('#editor', {...some options});

Now, I would like to get this editor instance when only having the element available, eg something like const editor = Quill.existingEditorFromElement('#editor');现在,我想在只有元素可用时获取这个编辑器实例,例如const editor = Quill.existingEditorFromElement('#editor');

The reason is that I am building a component that can be plugged into existing websites that enhances their editors, and I need a way to get their editor instance.原因是我正在构建一个可以插入现有网站的组件,以增强他们的编辑器,我需要一种方法来获取他们的编辑器实例。

This can be done by using Quill.find('#editor');这可以通过使用Quill.find('#editor');来完成。 , see https://quilljs.com/docs/api/#find-experimental ,请参阅https://quilljs.com/docs/api/#find-experimental

According to Quill API Documentation you can get the editor instance by getting the DOM element by its ID (or classname or tagname...), and inserting it inside the find function.根据Quill API Documentation ,您可以通过获取 DOM 元素的 ID(或类名或标记名...)并将其插入到 find 函数中来获取编辑器实例。

Example:例子:

var div = document.getElementById('editor');
var quill_instance = Quill.find(div);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM