百度編輯器Ueditor 初始化加載內容失敗解決辦法

項目上有用到百度文本編輯器ueditor,在頁面加載的時候初始化編輯器內容時候,使用javascript

$.document.ready(function()java

{編輯器

  UE.getEditor('editor').setContent('歡迎光臨');工具

})ui

setContent方法沒法加載內容,提示編輯器爲空,後來想一想,多是編輯器尚未加載完就執行此腳本致使的。後在網上找資料,能夠判斷ueditor編輯器完成加載後再加載內容:spa

核心內容以下code

var editor_a = new baidu.editor.ui.Editor(editorOption);
    editor_a.render('myEditor');
    editor_a.ready(function() {
        editor_a.setContent($('#content').val());
    });ip

 

具體例子:element

$ (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賦值
} ) ;
 
相關文章
相關標籤/搜索