判断字符串中有多少汉字

如何判断字符串中有多少汉字代码实例:

<html xmlns="http://www.w3.org/1999/xhtml" >
 <head> 
<title>标题页</title> 
</head> 
<body> 
<script language="JavaScript"> 
function cal(str) {    
 re=/[u4E00-u9FA5]/g; 
 //测试中文字符的正则    
 if(re.test(str))        
//使用正则判断是否存在中文    
 return str.match(re).length //返回中文的个数     
else     
return 0 } 
</script> 
<input onBlur="alert(cal(this.value))">
</body> 
 </html>
原文地址:https://www.cnblogs.com/vinplezhang/p/3844197.html