- 我有数据库中的数据。
- 在我的 js 文件中,我想更改 CKEditor 文本编辑器的值。
- 我的值是原始 html。
- 我希望将此原始值写入空的 CKEditor 文本编辑器。
我尝试了这些,但总是出现未定义的函数错误:
CKEDITOR.instances.myEditorID.insertHtml( '<p>This is a new paragraph.</p>' );
CKEDITOR.instances.myEditorID.setData( '<p>This is the editor data.</p>' );
我也尝试过,但仍然出现未定义的函数错误:
CKEDITOR.instances.YOUREDITORID.updateElement();
alert( document.getElementById( 'YOUREDITORID' ).value );
我尝试使用“editor”、“editor1”、“editor2”而不是 myEditorID,但仍然对我不起作用。
提前致谢。
- -更新 - -
这是我的 ckeditor 文本编辑器的 html:
<textarea id="myEditorID" name="myEditor"></textarea>
<script type="text/javascript">
$(function () {
var myEditor = $('#myEditorID');
myEditor.ckeditor({
height: 200,
extraPlugins: 'charcount',
maxLength: 2000,
toolbar: 'TinyBare',
toolbar_TinyBare: [
['Bold','Italic','Underline'],
['Undo','Redo'],['Cut','Copy','Paste'],
['NumberedList','BulletedList','Table'],['CharCount']
]
}).ckeditor().editor.on('key', function(obj) {
if (obj.data.keyCode === 8 || obj.data.keyCode === 46) {
return true;
}
if (myEditor.ckeditor().editor.document.getBody().getText().length >= 2000) {
alert('You have reached the maximum char length');
return false;
}
});
});
</script>