Limit the number of character in tinyMCE

后端 未结 16 949
心在旅途
心在旅途 2020-11-29 07:44

Im using tinyMCe for my project.Everything is working fine but now i want to restrict the number of character that will be insert into tinyMce text

16条回答
  •  有刺的猬
    2020-11-29 07:54

    Answers above were great! I've made a small amendment so that we can set max_chars by adding it as an attribute to textarea element itself

    setup : function(ed) {
            ed.onKeyDown.add(function(ed, evt) {
                //if ( $(ed.getBody()).text().length+1 > ed.getParam('max_chars')){
                if ( $(ed.getBody()).text().length+1 > $(tinyMCE.get(tinyMCE.activeEditor.id).getElement()).attr('max_chars')){
                    evt.preventDefault();
                    evt.stopPropagation();
                    return false;
                }
            });
        } 
    

提交回复
热议问题