如何使用javascript计算DIV中的字符数 [英] How to count the number of characters in a DIV with javascript

查看:85
本文介绍了如何使用javascript计算DIV中的字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我希望能够使用javascript / jquery计算Div中显示的字符数。例如

Hi I want to be able to count the number of displayed characters in a Div with javascript/jquery. For example

<div id=mydiv>
<p>This is my div!</p>
</div>

我希望得到数字15,因为div中有多少个字符,包括空格。

I want to get the number 15 since that's how many chars in the div including spaces.

谢谢!

推荐答案

$('#mydiv').text().length

应该这样做。

这篇关于如何使用javascript计算DIV中的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆