最近项目的富文本编辑器换成了UEditor,以为和kindeditor一样设置完就能实现字数限制(超过最大字数不能输入),实际上,UEditor只是给出了提示,并没有限制输入。所以就只能自给自足丰衣足食啦。
1.搜索ueditor.all.js中的maximumWords,找到以下段落:
countDom.innerHTML = errMsg; editor.fireEvent("wordcountoverflow");
2.下这段代码的下方,加上:
var content = editor.getContentTxt(); editor.setContent(content.substring(0,max)); editor.focus(true);
如果是min版的js,在对应位置加上:
,content = a.getContentTxt(),a.setContent(content.substring(0,d)),a.focus(true)
这种方法有个问题,就是因为是js的substring控制的,在输入超过最大字数时,会先显示出内容,然后再回退,不大好看,等我研究出来再补上╮(╯▽╰)╭