function GetCharLength(str){
var iLength = 0; //记录字符的字节数
for(var i = 0;i<str.length;i++){//遍历字符串中的每个字符
if(str.charCodeAt(i) >255){ //如果当前字符的编码大于255
iLength += 2; //所占字节数加2
}else{
iLength += 1; //否则所占字节数加1
}
}
return iLength; //返回字符所占字节数
}
//若字符串长度超过要求,弹窗提示
function CutStr(){
//获取要处理的字符串
var str = document.getElementById("zj").value;
if(GetCharLength(str)>10){
alert("字符串长度超过10!");
return;
}
}