计算字符长度
function checkCharacterLength(str){
var len = 0;
for(var y=0;y<str.length;y++){
var strLength = str.charCodeAt(y);
if(strLength >= 0 && strLength <= 128){
len += 1;
}else{
len += 3;
}
}
return len;
}
var characterLength = 0;
characterLength = checkCharacterLength($("#id").val().trim());
if(characterLength > 20){
alert("字符超出范围");
return false;
}
校验字符长度
最新推荐文章于 2024-07-25 02:04:28 发布