項目上有用到百度文本編輯器ueditor,在頁面加載的時候初始化編輯器內容時候,使用
$.document.ready(function()
{
UE.getEditor('editor').setContent('歡迎光臨');
})
setContent方法無法加載內容,提示編輯器為空,后來想想,可能是編輯器還沒有加載完就執行此腳本導致的。后在網上找資料,可以判斷ueditor編輯器完成加載后再加載內容:
核心內容如下
var editor_a = new baidu.editor.ui.Editor(editorOption);
editor_a.render('myEditor');
editor_a.ready(function() {
editor_a.setContent($('#content').val());
});
具體例子:
$
(document
).
ready
(
function
(
)
{
// 自定義的編輯器配置項,此處定義的配置項將覆蓋editor_config.js中的同名配置
var editorOption = {
//這里可以選擇自己需要的工具按鈕名稱,此處僅選擇如下五個
toolbars : [ [ 'FullScreen' , 'Source' , 'Undo' , 'Redo' , 'Bold' , 'forecolor' , 'link' , 'highlightcode' ] ] ,
//focus時自動清空初始化時的內容
autoClearinitialContent : true ,
//關閉elementPath
elementPathEnabled : false
} ;
var editor_a = new baidu. editor. ui. Editor (editorOption ) ;
editor_a. render ( 'myEditor' ) ;
editor_a. ready ( function ( ) {
editor_a. setContent ($ ( '#content' ). val ( ) ) ; //賦值給UEditor
} ) ;
$ ( '#title' ). val (title ) ; //title賦值
} ) ;
// 自定義的編輯器配置項,此處定義的配置項將覆蓋editor_config.js中的同名配置
var editorOption = {
//這里可以選擇自己需要的工具按鈕名稱,此處僅選擇如下五個
toolbars : [ [ 'FullScreen' , 'Source' , 'Undo' , 'Redo' , 'Bold' , 'forecolor' , 'link' , 'highlightcode' ] ] ,
//focus時自動清空初始化時的內容
autoClearinitialContent : true ,
//關閉elementPath
elementPathEnabled : false
} ;
var editor_a = new baidu. editor. ui. Editor (editorOption ) ;
editor_a. render ( 'myEditor' ) ;
editor_a. ready ( function ( ) {
editor_a. setContent ($ ( '#content' ). val ( ) ) ; //賦值給UEditor
} ) ;
$ ( '#title' ). val (title ) ; //title賦值
} ) ;