//英文标题按单词截取(参数说明 text:要截取的英文 len:要截取的长度)
function sliceEnglish(text,len) {
//如果要截取文本的长度小于或者等于要截取的长度,则不进行截取,直接返回文本
if(text.length < len) {
return text;
} //文本的长度大于要截取的长度,进行截取
else {
text = text.substr(0,len);
// 以空格切分字符串
var textArr = text.split(" ");
// 最后一个字符长度
var lastLen = textArr.pop().length;
if(lastLen > 3) {
return text.substr(0,text.length-lastLen-1)+' ...';
} else if(lastLen === 3 ){
return text;
}else{
var lastTwoLen = textArr[textArr.length - 1].length;
return text.substr(0,text.length-lastLen-lastTwoLen-2)+' ...';
}
}
}
$(".plan_content ul.list_ul li").each(function(){
var textle=sliceEnglish($(this).find("h3").text(),25);
$(this).find("h3").text(textle)
})