解决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变量,成功。




  • 2017-12-25 11:07:58

    mogodb 备份

    error connecting to db server: server returned error on SASL authentication

  • 2017-12-25 15:53:15

    MongoDB3.4版本配置详解

    配置文件方面,mongod和mongos有很多相同之处,下文中如有区别之处将会特别指出。 在一个节点上,通常同时启动mongod和mongos进程是正常的,他们之间不存在资源竞争,但是为了避免冲突,我们希望它们使用各自的配置文件,比如mongod.conf、mongos.conf;mongodb的某些平台下的安装包中没有自带配置文件,需要开发者自己创建。