我正在尝试从数据库绑定(bind) CK 编辑器中的数据。但它也不能正常工作,数据获取但不显示,仅在 Google Chrome 中单击检查元素时显示。
HTML
<textarea id="input" name="input"></textarea>
JS
<script>
$(document).ready(function () {
$("#input").ckeditor();
});
function BindData() {
$("#input").val('This is CK Editor Demo');
}
BindData();
</script>
链接 Here
最佳答案
首先,你必须等待 DOM 准备好,然后你必须等待编辑器准备好,最后你可以绑定(bind)你的数据:
// Wait for DOM to be ready.
$( document ).ready( function() {
// Create an instance of the editor.
$( '#input' ).ckeditor( function( textarea ) {
// When the instance is ready, set some data.
$( textarea ).val( 'This is CK Editor Demo!' );
} );
} );
或者使用外部方法:
function BindData() {
$( '#input' ).val( 'This is CK Editor Demo!' );
}
// Wait for DOM to be ready.
$( document ).ready( function() {
// Create an instance of the editor.
$( '#input' ).ckeditor( function() {
// When the instance is ready, set some data.
BindData();
} );
} );
阅读official guide适用于新的 jQuery 适配器(自 4.2 起)。
关于javascript - CK 编辑器上未获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18230491/