在javascript标签中加入如下代码
$(document).ready(function(){
$(".p_name").each(function(i){
var divH = $(this).height();
var $p = $("p", $(this)).eq(0);
while ($p.outerHeight() > divH) {
$p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
};
});
});
样式
.p_name {
text-align: left;
margin-left: 10px;
margin-right: 10px;
height: 36px;
width:230px;
}
HTML
<div class="p_name"><p>LV包包 | 名牌包包,时尚简约,仅剩22个赶紧出手吧名牌包包,时尚简约,仅剩22个赶紧出手吧名牌包包,时尚简约,仅剩22个赶紧出手吧</p></div>
原创文章转载请注明出处:http://blog.csdn.net/tangcheng_ok