ckeditor字数限制

var maxlength = 200;
   _editor=CKEDITOR.replace("ckeditor",{height:'130px'});
   _editor.on('key',function(event){
		var oldhtml = _editor.document.getBody().getHtml();
		var description = oldhtml.replace(/<.*?>/ig,"");
		var etop = $("#cke_1_top");
		var _slen = maxlength-description.length;
		var canwrite = $("");
		if(etop.find("#canwrite").length<1){
			canwrite.css({border:'1px #f1f1f1 solid','line-height':'28px',color:'#999'});
			etop.prepend(canwrite);
		}
		var _label = etop.find("#canwrite");
		if(description.length>maxlength){
			//alert("最多可以输入"+maxlength+"个文字,您已达到最大字数限制");
			_editor.setData(oldhtml);
			_label.html("还可以输入0字");
		}else{
			_label.html("还可以输入"+_slen+"字");
		}
	});

  

转载于:https://www.cnblogs.com/cestbon/p/4058909.html

你可能感兴趣的:(ckeditor字数限制)