在统计字数的时候很烦恼修改如下
就是个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> </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>