百度编辑器Ueditor 初始化加载内容失败解决办法
2015-12-30 17:05
465 查看
项目上有用到百度文本编辑器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赋值
});
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 //是否焦点
$.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赋值
});
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 //是否焦点
相关文章推荐
- EasyUI 获取行ID,符合条件的添加样式
- ReentrantLock实现自己的BlockingQueue
- [CSS3] Media Query & Responsive Design
- WeUI logo专为微信设计的 UI 库 WeUI
- The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class
- android picke ui
- 063 - Unique Paths II
- com.google.protobuf.InvalidProtocolBufferException: Message missing required fields: callId, status
- 062 - Unique Paths
- how to write one native program based on android source build system
- 关于UIView的autoresizingMask属性的研究
- Android漂亮的UI库集合
- 给UICollectionView添加头视图
- 70.UISearchController(搜索栏)
- UIButton要注意的地方
- PHP文件包含语句 include、include_once、require、require_once
- 292. Nim Game My Submissions Question
- php中include和require的区别
- Access restriction: The constructor SunJCE() is not accessible due to restriction on required librar
- 百度在线文本编辑器ueditor