//英文標題按單詞截取(參數說明 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)
})