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) {
                   var strValue=editor.text();
                    editor.text("");
                    editor.appendHtml(strValue.substring(0,30));
                }
            }
        });
        editor.sync();
    });
},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值