Ueditor--富文本编辑器

使用步骤如下:

1.引入插件

<script type="text/javascript" src="{{ static_url('ueditor/ueditor.config.js') }}"></script>
<script type="text/javascript" src="{{ static_url('ueditor/ueditor.all.js') }}"></script>
<script type="text/javascript" src="{{ static_url('ueditor/ueditor.parse.js') }}"></script>

2.在html页面中需要显示富文本编辑器的地方,添加如下代码:

<label>内容详情:</label>
//这行代码在你需要用到的表单元素写上,ueditor会识别到然后实例化一个编辑器到这里的
<script id="editor" type="text/plain" name="content"></script>
<p class="showInfo"></p>

3.创建编辑器

<script>
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')
    //就能拿到相关的实例
    var ue = UE.getEditor('editor', {
        initialFrameHeight: 300,
        initialFrameWeight: 100,
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo', 'bold']
        ],
        //autoHeightEnabled: true,
        //autoFloatEnabled: true,
    });
    //初始化编辑器 (该处用于设置编辑器回显值)
    ue.ready(function () {
        //ue.setContent(formData.content);
        ue.setContent("我是编辑器初始的内容...");
    });
</script>

  到这一步你基本的配置就完成了。可以使用编辑器了。

4.但是如果ueditor支持图片、文档、音乐等文件上传功能,如果你想要配置上传路径,可以修改 ueditor/jsp/config.json。这个文件对于每一个配置项,都明确的文字说明。附上一段图片上传的配置吧:

<script>
/* 上传图片配置项 */
"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
"imageFieldName": "upfile", /* 提交的图片表单名称 */
"imageMaxSize": 2048000, /* 上传大小限制,单位B */
"imageAllowFiles": [".png", ".jpg",".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
"imageCompressEnable": true, /* 是否压缩图片,默认是true*/
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
"imageUrlPrefix": "", /* 图片访问路径前缀 */
"imagePathFormat":"_images/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
</script>

如果你没有自己的文件管理服务器的话你可以直接修改 imageUrlPrefix 这个属性,也就是域名就可以了,他会创建一个文件夹来保存你上传的文件,你也可以修改他的imagePathFormat 属性来修改他的路径。

5.你如果觉得界面功能太多想去掉一些的话可以自定义界面的。只要在ueditor/ueditor.config.js的toolbar中删改配置即可,代码如下:他的代码如下:

//工具栏上的所有的功能按钮和下拉框,可以在new编辑器的实例时选择自己需要的重新定义  

<script>
toolbars: [[
           'fullscreen', 'source', '|', 'undo', 'redo', '|',
           'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
           'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
           'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
           'directionalityltr', 'directionalityrtl', 'indent', '|',
           'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
           'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
           'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
           'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
           'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
           'searchreplace', 'help', 'drafts'
]]  那些自己觉得不需要的去掉就行了
</script>

附加:

1.接收富文本框的内容

content1 = ue.getContent(),
content2 = ue.getContentTxt(),

content1得到的内容会有标签,content2得到的内容没有标签。 

2.下面是转载的

在渲染 ueditor 的时候,将 ueditor 交给一个全局变量。
<script>
var ue = UE.getEditor('container');
str = ue.getContent();直接获取文本中的内容
</script>

百度编辑器UEditor常用设置函数大全
在线文档对UEditor说明不够全面,收集了一些常用的方法和基本设置,以供参考。
<script>
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 //是否焦点
</script>


 

猜你喜欢

转载自blog.csdn.net/qq_34802511/article/details/82692338