Page

[ueditor]百度编辑器ueditor几个常用的api方法

1193Anson16-08-27


今天使用js获取ueditor里面的编辑框script代码,不知道怎么获取,最后在官网发现可以使用var html = ue.getContent(); 来获取html内容,另外我把其他常用的api列了出来。

常用方法

实例化编辑器到id为 container 的 dom 容器上:详细


var ue = UE.getEditor('container');


设置编辑器内容:详细


ue.ready(function() {
    ue.setContent('<p>hello!</p>');});


追加编辑器内容:详细


ue.ready(function() {
    ue.setContent('<p>new text</p>', true);});


获取编辑器html内容:详细


ue.ready(function() {
    var html = ue.getContent();});


获取纯文本内容:详细


ue.getContentTxt();


获取保留格式的文本内容:详细


ue.getPlainTxt();


获取纯文本内容:详细


ue.getContentTxt();


判断编辑器是否有内容:详细


ue.hasContents();


让编辑器获得焦点:详细


ue.focus();


让编辑器获得焦点


ue.blur();


判断编辑器是否获得焦点:详细


ue.isFocus();


设置当前编辑区域不可编辑:详细


ue.setDisabled();


设置当前编辑区域可以编辑:详细


ue.setEnabled();


隐藏编辑器:详细


ue.setHide();


显示编辑器:详细


ue.setShow();


获得当前选中的文本:详细


ue.selection.getText();


常用命令:详细

在当前光标位置插入html内容


ue.execCommand('inserthtml', '<span>hello!</span>');


设置当前选区文本格式:详细


ue.execCommand('bold'); //加粗ue.execCommand('italic'); //加斜线ue.execCommand('subscript'); //设置上标ue.execCommand('supscript'); //设置下标ue.execCommand('forecolor', '#FF0000'); //设置字体颜色ue.execCommand('backcolor', '#0000FF'); //设置字体背景颜色


回退编辑器内容:详细


ue.execCommand('undo');


撤销回退编辑器内容:详细


ue.execCommand('redo');


切换源码和可视化编辑模式:详细


ue.execCommand('source');


选中所有内容:详细


ue.execCommand('selectall');


清空内容:详细


ue.execCommand('cleardoc');


读取草稿箱


ue.execCommand('drafts');


清空草稿箱


ue.execCommand('clearlocaldata');