KindEditor设置字数限制(+光标问题解决)

//参考 https://blog.csdn.net/myweishanli/article/details/25800185
initKindEditer : function() {
    KindEditor.ready(function(K) {
        var editor = K.create('#detail', {
            cssPath : '',
            uploadJson : '/common/uploadImgAjax',
            fileManagerJson : '',
            allowFileManager : true,
            filterMode : false,// 控制kindeditor编辑器不过滤任何标签
            items : [ 'source', '|', 'undo', 'redo', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste',
                'table', '|', 'formatblock', 'justifyleft', 'justifycenter', 'justifyright', 'lineheight',
                '|', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', '|',
                'selectall', '-', 'title', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', '|',
                'textcolor', 'bgcolor', 'bold', 'italic', 'underline', 'strikethrough', 'removeformat',
                '|', 'image', 'hr', 'emoticons', 'link', 'unlink' ],
            afterCreate : function() {
                this.sync();
            },
            afterBlur : function() {
                this.sync();
            },
            //限制字数 30字以内
            afterChange : function() {
                //$('.word_count1').html(this.count()); //字数统计包含HTML代码
                //$('.word_count2').html(this.count('text'));//字数统计包含纯文本、IMG、EMBED,不包含换行符,IMG和EMBED算一个文字
                if(this.count('text') > 30) {
                    editor.text("");
                    editor.appendHtml($.trim(editor.text()));
                }
            }
        });
        editor.sync();
    });
},

猜你喜欢

转载自blog.csdn.net/qq_31459039/article/details/82907229