我用过这段代码。
此行必须在您创建 WYSIHTML5 对象之后:
$('.wysihtml5-sandbox').contents().find('body').on("keyup",countChars);
函数“countChars”定义为:
function countChars() {
var text = $('.wysihtml5-sandbox').contents().find('body').html().replace(' ',' '); //Remove space tags
var limit = 50; //Max text lenght
if(text.length > limit) {
//Your action when it's invalid
} else {
//Your action when it's valid
}
//In my case this is a span where the number is show
var remains = limit - text.length;
$('#char-counter').html(String(remains));
}
我希望它可以帮助你!