String.prototype.cutstr = function(len){
var num = this.length, count=0, res = '';
for (var i=0; i<num && count<len; i++) {
if( count+0.5 >= len) return res;
var ch = this.charCodeAt(i);
res += this[i];
if ( ch > 0 && ch < 128 ){
count+=0.5;
if ( count + 0.5 >= len) return res;
}else{
count++;
}
}
return res;
};
//测试一下下
var str = 'a华人ada中文字';
alert(str.cutstr(5)); //a华人ada中