我使用PHP在我的视图中创建ckeditori,我使用mvc框架,所以这是最简单的方法。
In my controller:
$data['text_editor'] = array(
'ckfinder' => array( 'path' => './assests/ck/ckfinder'),
'id' => 'text',
'path' => './assests/ck/ckeditor',
'config' => array(
'toolbar' => "Full",
'filebrowserImageUploadUrl' => base_url().'baseController/ckupload' )
);
$this->load->view('view' , $data ) ;
in view:
<textarea name="text" id="text" ></textarea>
<?php
echo display_ckeditor($text_editor);
?>
现在我想用js获取编辑器的值:
function get_value(){
alert(CKEDITOR.instances['text'].getData());
}
我也试过了:
CKEDITOR.instances['text_editor'].getData()
但是它不工作,我得到了这个错误:
TypeError: CKEDITOR.instances.text is undefined
alert(CKEDITOR.instances['text'].getData());
应该可以:
CKEDITOR.instances.text.getData();
如果没有,我的猜测是您可能试图在创建实例之前运行get_value函数,这会导致undefined
错误。
也许试试:
CKEDITOR.on('instanceReady', function() {
CKEDITOR.instances.text.getData();
});