截取字符串显示指定长度,超过部分用省略
function getInterceptedStr(sSource, iLen) { if (sSource.replace(/[^\x00-\xff]/g, "xx").length <= iLen) { return sSource; } var str = ""; var l = 0; var schar; for (var i = 0; schar = sSource.charAt(i); i++) { str += schar; l += (schar.match(/[^\x00-\xff]/) != null ? 2: 1); if (l >= iLen) { str += "...."; break; } } return str;}