1

我在网上搜索并查看了有关如何计算字符的 API Docs,我目前正在使用这个:$('.test').val().length;

但是,它根本不起作用。

我的 div 看起来像这样:<div class="test">Count These Letters</div>

我希望$('.test').val().length;返回19,但它返回1......我是否使用了错误的功能?

4

1 回答 1

6

对于文本,您需要.text(),如下所示:

 $('.test').text().length
于 2013-07-19T14:28:28.117 回答