主题: <p>&nbsp;&nsp;</p>类型的文本,在读取到编辑器时,&nbsp;会被过滤掉

在统计字数的时候很烦恼修改如下

就是个js替换 没招了





<script type="text/javascript">
    var flag=false;
    var editor1 = null;
    KindEditor.ready(function(K) {
            editor1 = K.create('textarea[name="contents"]', {
            cssPath : '${ctx}/js/kindeditor/plugins/code/prettify.css',
            uploadJson : '${ctx}/js/kindeditor/jsp/upload_json.jsp',
            //fileManagerJson : '${ctx}/js/kindeditor/jsp/file_manager_json.jsp',
            allowFileManager : true,
            items:[
                        'source','preview','cut', 'copy', 'paste',
                        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|','image',
                        'batchFile','table', 'hr', 'emoticons',   'pagebreak',
                        'link', 'unlink', '|', 'about'
                ],
            afterCreate : function() {
                var self = this;
                self.sync();
            },
            afterChange : function() {
                //K('.word_count1').html(this.count());
                //K('.word_count2').html(1000-this.count());
                 //限制字数
             if(editor1!=null  &&editor1.isEmpty() ){
                 var c = editor1.html();
                 c = c.replace(/\s+/g, "");
                 //c = c.replace(/<\/?.+?>/g,"");
                   c = c.replace(/[\r\n]/g, "");
                 if(c=='<p>&nbsp;</p>' ){
                     editor1.text("");
                 }
             }

                 
              if(this.count() > 4000) {
                   K('#normal').html(" 您输入的字已超过4000个,请酌情删减!<br />");   
                   flag=true;
               } else{
                      //if(editor1.isEmpty()) $("#contents").val("");
                   K('#normal').html(" 您当前输入了 <span class='word_count1'>"+(this.count())+"</span> 个文字,还能输入<span class='word_count2'>"+(4000-this.count())+"</span> 个文字。(字数统计包含HTML代码。)<br />");
                      flag=false;
               }
            }
        });
        prettyPrint();
    });
    function resetText(){
        editor1.text("");
    }
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值