我有我的内联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 中获取突出显示/选定的文本
$("#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
}
关于javascript - 获取 CKEDITOR 5 中突出显示/选定的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196777/