ueditor使用常见问题汇总
2022-07-221、更改字数限制
ueditor.all.js 查找或者全局查找 maximumWords 默认10000个字符,或者是1e4 即 10的四次方,更改成1e5或者100000一般足够用了
2、草稿箱加载,恢复上次编辑的内容
ueditor.config.js配置文件 toolbars下 添加 drafts
3、使用代码段pre页面报错(pre标记中如果有换行)或者 内容包含<>这种尖括号,保存后,再次使用setContent把内容塞进编辑器编辑,发现内容<>后的内容都消失了
初始化的时候可以把内容存储到隐藏的pre标记中
<div style='display: none'><pre id='hiddenContent'>mycontentxxxxxxxxxx</pre></div>
var ue = UE.getEditor('content');
ue.ready(function() {
ue.setContent($("#hiddenContent").val())
});
ue.addListener('ready', function() {
this.focus()
});4、在粘贴文本(纯文本)的时候,会自动给文本加上<span>标签,并给<span>带上了white-space: nowrap;的样式,即不自动换行
找到文件umeditor.js 文件UE.plugins.paste = function () {},修改里面的内容把white-space:nowrap删掉
5、常用代码
//追加编辑器内容:
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');