前言:百度富文本编辑器的使用
一、引用富文本编辑器的JS文件
<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" src="/ueditor/lang/zh-cn/zh-cn.js"></script>
二、富文本编辑器HTML
<div class="col-sm-8" style="width:600px;">
<textarea id="intro" placeholder="按步骤描述您的需求及审核稿件标准!" name='intro' style="width:600px;height:350px;"></textarea >
</div>
三、JS配置富文本编辑器
var ue = UE.getEditor('intro',{initialFrameWidth:600,initialFrameHeight:300,zIndex:0,toolbars: [
[
'undo', //撤销
'redo', //重做
'bold', //加粗
'indent', //首行缩进
'selectall', //全选
'removeformat', //清除格式
'time', //时间
'date', //日期
'justifyleft', //居左对齐
'justifyright', //居右对齐
'justifycenter', //居中对齐
'justifyjustify', //两端对齐
'forecolor', //字体颜色
'backcolor', //背景色
'imagecenter', //居中
]
] });
注意事项:
①intro为文本域的ID==》实例化编辑器的ID的容器上
②initialFrameWidth:富文本显示的宽度
③initialFrameHeight:富文本显示的高度
③toolbars:显示的菜单
四、获取内容
判断编辑器的内容是否为空:
1、获取编辑器的HTML内容
var htmls=false;
ue.ready(function() {
var html = ue.getContent();
if(html=='' || html==undefined){
htmls=false;
}else{
htmls= true;
}
});
②//判断是否为fasle
if(htmls==fasle){
alert('内容不能为空!');
return false;
}