javascript如何统计一段文字的字数

来源:百度知道 编辑:UC知道 时间:2024/06/06 10:36:15
有这个方法吗?

<script type="text/javascript">
function GetLen(res)
{
var txtID = document.getElementById(res);
alert(txtID.value.length);

}
</script>

<input type="button" onclick="GetLen('txt')" value="Get" />
<textarea id="txt">
Contents
</textarea>