RT.
不废话,直接上代码.
window.onload = function(){
var text = document.getElementById('infoText'),
str = text.innerHTML,
textLeng = 150; //这里设置需要截取的文字的长度.
if(str.length > textLeng ){
text .innerHTML = str.substring(0,textLeng )+"...";
}
}
这种处理方法是在文字比较多且需要换行的情况,如果不需要换行,可以直接通过
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
css设定来实现.当然容器需要设定好固定的宽度.