1 <!DOCTYPE html>
2 <html>
3 <head lang="en">
4 <meta charset="UTF-8">
5 <title>统计中文字符个数-通用</title>
6 </head>
7 <body>
8 <input type="text" onblur="alert(c(this.value))"/>
9 <script>
10 var c = function (str) {
11 re = /[u4E00-u9FA5]/g;
12 if (re.test(str)) {
13 return str.match(re).length
14
15 } else {
16
17 return 0
18 }
19
20 }
21 </script>
22
23 </body>
24 </html>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>统计中文字符个数-通用</title>
</head>
<body>
<input type="text" onblur="alert(c(this.value))"/>
<script>
var c = function (str) {
re = /[u4E00-u9FA5]/g;
if (re.test(str)) {
return str.match(re).length
} else {
return 0
}
}
</script>
</body>
</html>