转载自:http://developer.51cto.com/art/201312/425414.htm
1、实现字符串长度截取(可中英文混合)
function cutstr()
{
var str = document.all.strWord.value; //原字符串
var len = document.all.strLen.value; //截取长度
var temp;
var icount = 0;
var patrn = /[^\x00-\xff]/;
var strre = "";
for (var i = 0; i < str.length; i++)
{
if (icount < len)
{
temp = str.substr(i, 1);
if (patrn.exec(temp) == null)
{
icount = icount + 1
}
else
{
icount = icount + 2
}
strre += temp
}
else
{
break
}
}
alert(strre);
//return strre + "..."
}