js截取字符串显示引号两种方法
//截取字符串多余显示引号
var cutStrForNum = function (str, num) {
var len = 0;
for (var i = 0; i < str.length; i++) {
if (str[i].match(/[^\x00-\xff]/ig) != null) //全角
len += 2;
else
len += 1;
}
if (len >= num) {
newStr = str.substring(0, num) + "...";
}
return newStr;
};
//var n = 'fafasfafafafafafaf';cutStrForNum(n,24)
方法2
for (var r = 0; r < $(".text-content").length; r++) {
var i = $(".text-content")[r]
, s = $(".text-content").eq(r).text().length;
if (s > 50) {
var o = i.innerHTML.slice(0, 50) + "...";
i.innerHTML = o
}
}