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




  • 2020-02-22 13:58:50

    深入理解 requestAnimationFrame

    在Web应用中,实现动画效果的方法比较多,Javascript 中可以通过定时器 setTimeout 来实现,css3 可以使用 transition 和 animation 来实现,html5 中的 canvas 也可以实现。除此之外,html5 还提供一个专门用于请求动画的API,那就是 requestAnimationFrame,顾名思义就是请求动画帧。 为了深入理解 requestAnimationFrame 背后的原理,我们首先需要了解一下与之相关的几个概念:

  • 2020-02-22 17:35:14

    使用tweenjs写一个发牌的demo

    移动端h5的三大抽奖方式:转盘,老虎机,翻纸牌。 前两样demo比较多,用户也审美疲劳了。这次微信公众号要抽奖,于是调研了下翻纸牌。

  • 2020-02-22 17:45:43

    tweenjs简单快速学习

    tweenjs 是使用 JavaScript 中的一个简单的补间动画库,支持数字、对象的属性和 CSS 样式属性的赋值。 tweenjs 以平滑的方式修改元素的属性值,需要传递给 tween 要修改的值、动画结束时的最终值和动画花费时间(duration),之后 tween 引擎就可以计算从开始动画点到结束动画点之间值,从而产生平滑的动画效果。

  • 2020-02-22 17:47:12

    easeJs入门学习教程

    createjs中包含以下四个部分: EaselJS:用于 Sprites、动画、向量和位图的绘制,创建 HTML5 Canvas 上的交互体验(包含多点触控) TweenJS:用于做动画效果 SoundJS:音频播放引擎 PreloadJS:网站资源预加载

  • 2020-02-22 17:54:59

    最新FullCalendar中文文档

    Fullcalendar是一款用来管理日程安排、工作计划的日历工具,它功能非常强大而且非常实用。而目前网络上没有很好的中文文档,为了更好的和大家分享Fullcalendar的相关使用,即日起计划将Fullcalendar的英文文档翻译成中文版。

  • 2020-02-22 17:57:05

    nuxtjs支持api接口,serverMiddleware

    Who can’t relate to this: You’ve built a small portfolio page for someone, maybe a company, a friend or yourself. And the only API endpoint you’d need is one for a form. What now? Scaffolding a new service just for this one endpoint?

  • 2020-02-22 17:59:34

    FullCalendar插件的基本使用带详细配置翻译

    前段时间,一直在开发考勤系统,当时为满足设计的需求,选了好几个插件,最后决定采用Fullcanlendar的插件。感觉这个插件可以满足现阶段的功能开发需求