解决UEditor超出最大字数后只提示不限制的问题

2019-09-26 21:48:15

最近项目用到百度额UEditor文本编辑器,今天测试向我提出了一个问题。就是在输入的文字超过默认的最大字数限制之后,虽然提示“字数超过最大范围,服务器可能拒绝保存”,但是仍然可以点击保存按钮进行保存。



现在想要实现在达到最大字数的时候,就禁止再继续输入了。就像之前微博那样最大140字超过就不能输入那样。



查了官方文档,无果。然后百度到的答案几乎一致。如下图所示:


第一步:在ueditor.all.js中找到这两行注释掉

countDom.innerHTML = errMsg;

editor.fireEvent(“wordcountoverflow”)

第二步:在注释点的两行下面写上这三行就搞定了

var content = editor.getContentTxt();

editor.setContent(content.substring(0,maxwordsnum));

editor.focus(true);


然而,参照此方法并没有用,F12调试js代码发现,maxwordsnum

没有定义啊。



于是试着修改了一下这段代码




function setCount(editor,ui) {

                editor.setOpt({

                    wordCount:true,

                    maximumWords:10000,

                    wordCountMsg:editor.options.wordCountMsg || editor.getLang("wordCountMsg"),

                    wordOverFlowMsg:editor.options.wordOverFlowMsg || editor.getLang("wordOverFlowMsg")

                });

                var opt = editor.options,

                    max = opt.maximumWords,

                    msg = opt.wordCountMsg ,

                    errMsg = opt.wordOverFlowMsg,

                    countDom = ui.getDom('wordcount');

                if (!opt.wordCount) {

                    return;

                }

                var count = editor.getContentLength(true);

                if (count > max) {

//                    countDom.innerHTML = errMsg;

//                    editor.fireEvent("wordcountoverflow");

                    debugger;

                    var content = editor.getContentTxt();

                    editor.setContent(content.substring(0,max));

                    editor.focus(true);

                } else {

                    countDom.innerHTML = msg.replace("{#leave}", max - count).replace("{#count}", count);

                }

            }


其实只是将maxwordsnum修改成了max变量,成功。




  • 2018-03-21 22:28:02

    Java加密算法 AES

    AES 算法 对称加密,密码学中的高级加密标准 2005年成为有效标准

  • 2018-03-24 13:23:26

    Only the original thread that created a view hierarchy can touch its views

    很多网友在Android中使用多线程处理UI相关内容时可能会发现Logcat提示Only the original thread that created a view hierarchy can touch its views这样的错误,这主要是Android的相关View和控件不是线程安全的,我们必须做独立的处理这点比J2ME麻烦一些,这里Android给 我们提供了很多方法,有关线程的

  • 2018-03-26 18:05:09

    MYSQL OR与AND一起 的用法

    查询结果是id = 2且age = 20或者id=1SELECT * from student WHERE id = 1 or id = 2 AND age = 20;12

  • 2018-03-27 11:27:09

    Java中Set集合的使用

    Set类继承了Conllection类,是一种集合类。Set的实现类有三个,下面我们会一一来说这些的不一样。

  • 2018-03-27 11:36:58

    Java中数组、List、Set互相转换

    需要注意的是, Arrays.asList() 返回一个受指定数组决定的固定大小的列表。所以不能做 add 、 remove等操作,否则会报错。

  • 2018-03-27 16:37:57

    Java 8 将List转换为Map

    几个Java 8示例来向您展示如何将一个List对象转换为一个Map,以及如何处理重复的键

  • 2018-03-31 09:37:33

    Android Sqlite查询优化之一---运用索引

    最近笔者在做聊天功能模块,发现当本地聊天数据记录过大,以10万行数据进行了检索测试,发现时间太长了,要6s左右,但学着运用了下索引,时间大大提升,紧要几百毫秒就能完成. 以下内容,摘抄至网络