javascript - CK 编辑器上未获取数据

标签 javascript jquery html ckeditor

我正在尝试从数据库绑定(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/

相关文章:

php - IE 8 中的访问被拒绝 jquery 错误

javascript - 带有动态 id 的 jQuery 选择

javascript - 在填充的单元格中带有换行符的 Jquery Mobile 表

Html - 容器中的图像高度(百分比)

php - 可以向 WordPress 管理面板添加 css 修改吗?

php - Ajax调用总是以错误处理程序结尾

Javascript Eval 代码问题

javascript - 精确比较 $(window).height() 值与滚动的特定值

javascript - jQuery.ajax - 为什么它不起作用?

html - 当加载程序到达表单顶部时,表单位置正在改变