在CKEDITOR 5中获取突出显示/选定的文本 [英] Get the highlighted/selected text in CKEDITOR 5
本文介绍了在CKEDITOR 5中获取突出显示/选定的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的在线CKeditor
I have my Inline CKeditor
let globalEditor;
InlineEditor.create(document.querySelector("#textarea"), {
toolbar: {
items: ['heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', 'undo', 'redo']
}
}).then(editor => {
globalEditor = editor;
}).catch(err => {
console.error(err.stack);
});
我还有一个按钮,应该可以在ckeditor中获取突出显示/选定的文本
I also have a button that supposed to be getting the highlighted/selected text inside the ckeditor
$("#btnAddTag").click(function (e) {
e.preventDefault();
var editor = globalEditor;
var getText = editor.getSelection().getNative(); //I tried this but the *getSelection* is undefined
});
有什么建议吗?
推荐答案
已经解决了问题
const editor = globalEditor;
const selection = editor.model.document.selection;
const range = selection.getFirstRange();
for (const item of range.getItems()) {
console.log(item.data) //return the selected text
}
这篇关于在CKEDITOR 5中获取突出显示/选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文