//一个汉字相当于2个字符
function get_length(s){
var char_length = 0
for (var i = 0 i < s.length i++){
var son_char = s.charAt(i)
encodeURI(son_char).length > 2 ? char_length += 1 : char_length += 0.5
}
return char_length
}
function cut_str(stbr, len){
var char_length = 0
for (var i = 0 i < str.length i++){
var son_str = str.charAt(i)
encodeURI(son_str).length > 2 ? char_length += 1 : char_length += 0.5
if (char_length >= len){
var sub_len = char_length == len ? i+1 : i
return str.substr(0, sub_len)
break
}
}
}
// 截取15个字(30个字符)
// cut_str('aa啊啊啊啊啊啊啊啊啊啊啊啊啊k的啊是', 15)
</script>
var str = "<aiiqewr中国'1#387axes"var begin = 0
for(var i=0i<str.lengthi++){
if (str.charCodeAt(i) > 127) {
begin = i
break }
}
str = str.substring(i,i+1)