ueditor概述

它是由百度web前端研发部开发所见即所得富文本web编辑器,并且是基于BSD协议的开源产品,允许自由使用和修改
ueditor官网: http://ueditor.baidu/website/index.html。我们可以在官网下载地址中定制选择编辑器需要使用的功能,从而定制自己的编辑器



ueditor的使用

将下载下来的文件夹里面的UE文件目录导入到项目中,然后在jsp文件中的head标签中引入如下文件
<script src="UE/ueditor.config.js"></script>
<script src="UE/editor.all.js"></script>
<script src="UE/lang/zh-cn/zh-cn.js"></script>

<link rel="stylesheet" href="UE/themes/default/css/ueditor.css"/>


然后在body标签中使用js创建编辑器对象
<script id="myEditor" type="text/plain" style="width: 1007px;height: 500px"></script>

<script>
    //实例化编辑器到id为myEditor的容器中
    var ue = UE.getEditor("myEditor");
</script>


最后需要引入ueditor.jar包



ueditor常用的方法

在使用ueditor常用的方法之前,我们需要先获取ueditor对象,比如获取上面定义好的ueditor对象
<script>
    //获取ueditor编辑器
    var ue = UE.getEditor("myEditor");
</script>


常用方法列表
1. var ueditor = UE.getEditor("idval"): 实例化ueditor编辑器到id为idval的容器上并且获取该编辑器的实例对象赋值给ueditor;

2.ueditor.setContent(content"): 使用js设置编辑器的内容

3.ueditor.setContent("content",true):使用js追加内容

4.ueditor.getContent(): 使用js获取编辑器的内容

5.ueditor.getContentTxt(): 使用js获取纯文本内容(无html标签)

6.ueditor.getPlainTxt():使用js获取保留格式的文本内容

7.ueditor.hasContents():判断编辑器中是否写入了内容

8.ueditor.focus()/blur():让编辑器获得/失去焦点

9.ueditor.isFocus():判断编辑器是否获得了焦点

10.ueditor.setDisabled()/setEnabled():设置当前区域为不可编辑/可编辑状态

11.ueditor.setHide()/setShow():隐藏/显示当前编辑器

12.ueditor.selection.getText(): 获取当前选中的文本内容

更多推荐

ueditor编辑器的初次使用