var jmz = {};
jmz.GetLength = function(str) {
///<summary>获得字符串实际长度,中文2,英文1</summary>
///<param name="str">要获得长度的字符串</param>
var realLength = 0, len = str.length, charCode = -1;
for (var i = 0; i < len; i++) {
charCode = str.charCodeAt(i);
if (charCode >= 0 && charCode <= 128) realLength += 1;
else realLength += 2;
}
return realLength;
};
//调用的方法obj是jsvar的名字,num是要比较的字符串长度
function cutLength(obj,num){
var text = obj.getValue()+"";
var textLength;
if(num<jmz.GetLength(text)){
//alert(jmz.GetLength(text));
alert("您的个人简介过长,请保持在"+num+"个字符之内!");
textLength = text.substring(0,num);
//alert(textLength);
obj.setValue(textLength);
}
}