Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解码html实体的ckeditor字符计数 警报(CKEDITOR.instances.editor1.getData().replace(/]*>\s/g',).length);_Javascript_Ckeditor_Html Entities - Fatal编程技术网

Javascript 解码html实体的ckeditor字符计数 警报(CKEDITOR.instances.editor1.getData().replace(/]*>\s/g',).length);

Javascript 解码html实体的ckeditor字符计数 警报(CKEDITOR.instances.editor1.getData().replace(/]*>\s/g',).length);,javascript,ckeditor,html-entities,Javascript,Ckeditor,Html Entities,我使用这段代码检索写入编辑器的文本的字符数。 不幸的是,如果连续写入多个空格,它会变成,并且在写入一些字符(如á)时,它会被解释为á长度为8个字符,而不是1个字符 我的问题是如何增强这一行,以便在计算字符数之前解码html实体。不过,我找到了另一种方法: 警报(CKEDITOR.instances.editor1.getData().replace(/&[^&]*.\s/g,'x')。replace(/]*>\s/g',)。长度) HTMLEntity将变为1个字符(x) alert

我使用这段代码检索写入编辑器的文本的字符数。 不幸的是,如果连续写入多个空格,它会变成
,并且在写入一些字符(如
á
)时,它会被解释为
á长度为8个字符,而不是1个字符


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

不过,我找到了另一种方法:

警报(CKEDITOR.instances.editor1.getData().replace(/&[^&]*.\s/g,'x')。replace(/]*>\s/g',)。长度)

HTMLEntity将变为1个字符(x)

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