var codeLength = function (cname, num) {
var re = /^[0-9a-zA-Z]*$/g;
var cname = document.getElementsByClassName(cname);
for (var i = 0; i < cname.length; i++) {
var length = 0;
var now = cname[i].innerHTML;
var nowLength = cname[i].innerHTML.length;
for (var j = 0; j < nowLength; j++) {
if (re.test(now[j])) {
length += 0.5;
} else {
length += 1;
}
}
if (length > num) {
cname[i].innerHTML = cname[i].innerHTML.substr(0, num - 5) + "..."
}
}
}
网友评论