我用的是CKEditor5 classic和document type。
我有一個報告,我需要通過在文本中雙擊它來輸入其中一個報告庫的參數。為此,我需要找到光標的位置,并將參數放入該字段。
注意:光標位置可能在文本中間。
我需要用javascript給應用程序添加值。
<div id="ck5_Container_fldDescription" class="ck5_Container">
<div class="SMK form-control ck ck-content ck-editor__editable ck-rounded-corners ck-editor__editable_inline ck-blurred" tabid="4" name="ck5_fldDescription" subtype="CKEDITOR5" submod="DOCUMENT" id="ck5_fldDescription" dir="rtl" role="textbox" aria-label="Rich Text Editor. Editing area: main" lang="ar" contenteditable="true">
<h2><strong>asdfsadf</strong></h2>
<p>asdf</p>
<p>asdf</p>
<p>asdf</p>
<p>as</p>
<p>df</p>
</div>
</div>
function addText() {
var editor = document.getElementById("ck5_fldDescription");
//console.log(editor);
var RepName = $('#Rep .rowSelected').find("td").eq(1).html().trim();
//console.log('RepName');
//console.log(RepName);
editor.model.change(writer => {
const selection = editor.model.document.selection;
const currentAttributes = selection.getAttributes();
const insertPosition = selection.focus;
writer.insertText(RepName, currentAttributes, insertPosition);
});
}
$('#Rep').dblclick(function() {
addText();
});
我的代碼如上,但它不能正常工作,你能幫助我嗎???