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




  • 2019-01-01 21:38:51

    php使用curl设置超时的重要性

    网站登录不了,原因是没有可用的 PHP 子进程来响应新的请求了。这可能是是由于PHP-curl 没有设置超时时间引起的。

  • 2019-01-01 21:42:34

    php-fpm 启动参数及重要配置详解

    如果file_get_contents请求的远程资源如果反应过慢,file_get_contents就会一直卡在那里不会超时。我们知道php.ini 里面max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm) 中,该参数不会起效。真正能够控制 PHP 脚本最大执行时间的是 php-fpm.conf 配置文件中的request_terminate_timeout参数。

  • 2019-01-08 14:35:50

    ueditor 特殊符号转义

    几个月前,就有同事跟我反馈,说磨途歌的留言板有问题。当时看了一下,她用的是谷歌浏览器,确实打不出中文,才按下一个字母,英文字母就从输入法的输入框中直接跳出来了,更换火狐浏览器就没这个问题。很奇怪的是,在我电脑上的火狐浏览器跟谷歌浏览器都没有问题,一开始还以为是她电脑的问题,就没在意了。