0

如何计算 JQuery 或 Javascript 中一对标签中的字符(不包括空格)?什么功能?

例如:

<pre id="mytext">This is the text.      This is the text.</pre>

如何知道 $("#mytext") 中有多少个字符或单词?

4

1 回答 1

7

像这样:

var chars = $('#mytext').text().replace(/ /g, '').length;

如果要排除任何空格,而不仅仅是空格:

var chars = $('#mytext').text().replace(/\s/g, '').length;
于 2009-11-19T12:47:37.960 回答