1.定义了一个UEditor编辑器
var ue= UE.getEditor('message');
2.使用setContent()方法清空,
ue.setContent('') ;
3.给富文本赋值
ue.setContent(text,false);//text为赋值的内容
4.设置富文本高度
ue.ready(function () { ue.setHeight(200); });
5.富文本初始化
<script id="message" name="message" type="text/plain"> </script>
js代码:
ue = UE.getEditor('message', { 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', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|', 'print', 'preview', 'searchreplace', 'drafts', 'help' ] ] });
// toolbars里面的值根据需要增减
6.富文本控制输入字数 在配置文件config.js中修改参数maximumWords
7.修改富文本宽度可变在配置文件config.js中修改参数initialFrameWidth为100%
8.在thymeleaf模板中富文本取值
<script id="message" name="remark" th:utext="${student.remark}" type="text/plain"> </script>
9.获取富文本内容
ue.getContentTxt();//不带格式的
ue.getContent();//带格式的