$().ready(function () {
var editor = UE.getEditor('editor', {
wordCount:true, //是否開啟字數統計
maximumWords:10, //允許的最大字符數
});
editor.addListener( 'contentChange', function( ) {
var str = editor.getContentTxt();
var leng = str.length;
if (leng > 200){
util.winAlert("錯誤,最多輸入兩百字");
}
});
});
傳過去之后利用strlen()函數發現字數仍然比預期的多,這是因為字符串中有html標簽,利用strip_tags();去除字符串的html標簽,就對了。(UTF-8編碼下的中文字符是3個字節)
參考文檔: https://ueditor.baidu.com/doc/