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


項目上有用到百度文本編輯器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時自動清空初始化時的內容
        autoClearinitialContenttrue,
         //關閉elementPath
         elementPathEnabledfalse
    };
    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賦值
});
 
 

try{
UE.getEditor('ueditor').ready(function() {
UE.getEditor('ueditor').setContent("內容"); //賦值給UEditor
});
}
catch(e)
{

}

 
http://www.cnblogs.com/treasurelife/p/3734104.html
 
 
 

在線文檔對UEditor說明不夠全面,收集了一些常用的方法和基本設置,以供參考。
1、創建編輯器
UE.getEditor('editor', {
initialFrameWidth:"100%" //初始化選項
})
精簡版
UE.getEditor('editor')
2、刪除編輯器
UE.getEditor('editor').destroy();
3、設置焦點
UE.getEditor('editor').focus();
4、獲取編輯器內容
UE.getEditor('editor').getContent()
5、編輯器是否有內容
UE.getEditor('editor').hasContents()
6、獲取編輯器內容純文本格式
UE.getEditor('editor').getContentTxt()
7、獲取帶格式的純文本
UE.getEditor('editor').getPlainTxt()
8、啟用編輯器
UE.getEditor('editor').setEnabled();
9、禁止編輯
UE.getEditor('editor').setDisabled('fullscreen');
10、獲取整個html內容
UE.getEditor('editor').getAllHtml()
11、常用設置
imageUrl:UEDITOR_HOME_URL + "../yunserver/yunImageUp.php", //圖片上傳接口
imagePath:"http://",

scrawlUrl:UEDITOR_HOME_URL + "../yunserver/yunScrawlUp.php",//塗鴉接口
scrawlPath:"http://",

fileUrl:UEDITOR_HOME_URL + "../yunserver/yunFileUp.php",//文件上傳接口
filePath:"http://",

catcherUrl:UEDITOR_HOME_URL + "php/getRemoteImage.php",//獲取遠程圖片接口
catcherPath:UEDITOR_HOME_URL + "php/",

imageManagerUrl:UEDITOR_HOME_URL + "../yunserver/yunImgManage.php",//圖片管理接口
imageManagerPath:"http://",

snapscreenHost:'ueditor.baidu.com',
snapscreenServerUrl:UEDITOR_HOME_URL + "../yunserver/yunSnapImgUp.php",//截圖接口
snapscreenPath:"http://",

wordImageUrl:UEDITOR_HOME_URL + "../yunserver/yunImageUp.php",//word圖片轉存接口
wordImagePath:"http://", //

getMovieUrl:UEDITOR_HOME_URL + "../yunserver/getMovie.php",//獲取視頻接口

lang:/^zh/.test(navigator.language || navigator.browserLanguage || navigator.userLanguage) ? 'zh-cn' : 'en',
langPath:UEDITOR_HOME_URL + "lang/",

webAppKey:"9HrmGf2ul4mlyK8ktO2Ziayd",
initialFrameWidth:860, //初始化寬度
initialFrameHeight:420, //初始化高度
focus:true //是否焦點

 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM