截取文本内容的实现方法

对于信息显示,只需显示一行或是其所在的标签不能超出一定范围,需要做限制(在拿到设计图时应该想到)

css实现的方法
{white-space:nowrap;
text-overflower:ecllipsis;
overflower:hidden;}
//当然需要设置宽度

jquery实现方法
 var num=$(".text_wrap").html();
 if(num.length>7){$(".text_wrap").html(num.substr(0,7)+"…")
     }//使用jquery截取class="text_wrap"的标签内容的前7个字符串

原文地址:https://www.cnblogs.com/wjh0916/p/4877561.html