0
alert(CKEDITOR.instances.editor1.getData().replace(/<[^>]*>|\s/g, '').length);

我正在使用此代码来检索写入编辑器的文本的字符数。不幸的是,如果连续写多个空格,它会变成&nbsp;,而当写一些字符时,例如á,它被解释为&aacute;8 个字符长而不是 1。

我的问题是如何在计算字符之前增强这一行以解码 html 实体。

4

1 回答 1

1

没关系,我找到了另一种方法:

alert(CKEDITOR.instances.editor1.getData().replace(/&[^&]*;|\s/g, 'x').replace(/<[^>]*>|\s/g, '').length);

htmlentities 变为 1 个字符 (x)。

于 2013-11-09T13:18:23.197 回答