jquery限制div字符长度,超出部分已“…”显示

1 $(".content").each(function(){  
2                              if($(this).text().length>100){
3                              $(this).text($(this).text().substring(0,100));
4                              $(this).html($(this).html()+'...');    
5                              }
6 })

 另一种循环截取例子:

 1 var count=$("#container_box").find("#content_index").length;
 2         for(i=0;i<count;i++){
 3             num=$("#container_box").find("#content_index").eq(i).text();
 4             text=$("#container_box").find("#content_index").eq(i);
 5             sub=text.text().length;
 6             alert(sub);
 7             if(sub>150){   
 8             text.text(text.text().substring(0,150));
 9             text.html(text.html()+'...'); 
10             }  
11         }
原文地址:https://www.cnblogs.com/mrcln/p/3791903.html