判断字符长度解决方法

WBOY
Release: 2016-06-13 13:14:58
Original
877 people have browsed it

判断字符长度
function checkLength(str)
{
var i,sum;
sum=0;
for(i=0; i {
if ((str.charCodeAt(i)>=0) && (str.charCodeAt(i) sum = sum + 1;
else
sum = sum + 2;
}
return sum;
}

里面的(str.charCodeAt(i)>=0) && (str.charCodeAt(i)
------解决方案--------------------
(str.charCodeAt(i)>=0) && (str.charCodeAt(i)表示的是一个以Unicode 编码为基准的字符
大于255好像是表示一个字,占两位

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!