【发布时间】:2009-11-19 12:44:03
【问题描述】:
如何计算JQuery或Javascript中一对标签内的字符(不包括空格)?什么功能?
例如:
<pre id="mytext">This is the text. This is the text.</pre>
如何知道$("#mytext")中有多少个字符或单词?
【问题讨论】:
标签: javascript jquery spaces
如何计算JQuery或Javascript中一对标签内的字符(不包括空格)?什么功能?
例如:
<pre id="mytext">This is the text. This is the text.</pre>
如何知道$("#mytext")中有多少个字符或单词?
【问题讨论】:
标签: javascript jquery spaces
像这样:
var chars = $('#mytext').text().replace(/ /g, '').length;
如果您想排除任何空格,而不仅仅是空格:
var chars = $('#mytext').text().replace(/\s/g, '').length;
【讨论】: