ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## find <span class="experimental">实验</span> <!-- Static method returning the Quill or [Blot](https://github.com/quilljs/parchment) instance for the given DOM node. In the latter case, passing in true for the `bubble` parameter will search up the given DOM's ancestors until it finds a corresponding [Blot](https://github.com/quilljs/parchment). --> 静态方法,给定一个DOM节点,返回对应的Quill或<a href="https://github.com/quilljs/parchment" target="_blank">Blot</a>实例。 返回后者时,参数`bubble`为true时,将向上搜索给定DOM的祖先节点,知道找到对应的<a href="https://github.com/quilljs/parchment" target="_blank">Blot</a>。 **方法** ```javascript Quill.find(domNode: Node, bubble: boolean = false): Blot | Quill ``` **示例** ```javascript var container = document.querySelector("#container"); var quill = new Quill(container); console.log(Quill.find(container) === quill); // Should be true quill.insertText(0, 'Hello', 'link', 'https://world.com'); var linkNode = document.querySelector('#container a'); var linkBlot = Quill.find(linkNode); ``` ## getIndex <span class="experimental">实验</span> <!-- Returns the distance between the beginning of document to the occurrence of the given [Blot](https://github.com/quilljs/parchment). --> 返回文档开始至给定<a href="https://github.com/quilljs/parchment" target="_blank">Blot</a>对象位置的距离。 **方法** ```javascript getIndex(blot: Blot): Number ``` **示例** ```javascript let [line, offset] = quill.getLine(10); let index = quill.getIndex(line); // index + offset should == 10 ``` ## getLeaf <span class="experimental">实验</span> <!-- Returns the leaf [Blot](https://github.com/quilljs/parchment) at the specified index within the document. --> 指定文档中的距离,返回对应的叶<a href="https://github.com/quilljs/parchment" target="_blank">Blot</a>实例。 **方法** ```javascript getLeaf(index: Number): Blot ``` **示例** ```javascript quill.setText('Hello Good World!'); quill.formatText(6, 4, "bold", true); let [leaf, offset] = quill.getLeaf(7); // leaf should be a Text Blot with value "Good" // offset should be 1, since the returned leaf started at index 6 ``` ## getLine <!-- Returns the line [Blot](https://github.com/quilljs/parchment) at the specified index within the document. --> 指定文档中的距离,返回行 <a href="https://github.com/quilljs/parchment" target="_blank">Blot</a>。 **方法** ```javascript getLine(index: Number): [Blot, Number] ``` **示例** ```javascript quill.setText('Hello\nWorld!'); let [line, offset] = quill.getLine(7); // line should be a Block Blot representing the 2nd "World!" line // offset should be 1, since the returned line started at index 6 ``` ## getLines <span class="experimental">实验</span> <!-- Returns the lines contained within the specified location. --> 返回指定位置包含的行。 **方法** ```javascript getLines(index: Number = 0, length: Number = remaining): Blot[] getLines(range: Range): Blot[] ``` **示例** ```javascript quill.setText('Hello\nGood\nWorld!'); quill.formatLine(1, 1, 'list', 'bullet'); let lines = quill.getLines(2, 5); // array witha a ListItem and Block Blot, // representing the first two lines ```