javascript - Get the highlighted/selected text in CKEDITOR 5
问题描述
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);
});
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
});
Any suggestions?
解决方案
Already fixed the problem
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
}
推荐阅读
- http - 无法访问前端应用程序中的自定义响应标头
- django - django 查询:获取只有“时间”大于 HH:mm 的对象,无论日期是什么?
- php - 社交名流:传递给 Illuminate\Auth\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\Contracts\Auth\Authenticatable,给定 null
- google-bigquery - Google BigQuery:INFORMATION_SCHEMA 在某些位置不可用
- ios - info.plist 中支持的接口方向似乎阻止了对 shouldAutorotate 的调用
- php - 如何使用php在数据库中生成唯一ID(MC0001)并且它不会在数据库中重复
- perl - 如何使用 html 创建按钮到 perl 中的符号链接文件?
- android - 如何根据自己的类别填充数据
- android - Ziggeo 错误 setPreviewTexture 使用 Fragment 失败
- java - arraylist 如何在内部使用数组存储不同的数据类型