<div class="tits" style="width:900px;">${item.note}</div>
//自动计算长度,并剔除html元素
$(".tits").each(function(i) {
var leg = 280;
$(this).html($(this).text());
var copyThis = $(this.cloneNode(true)).hide().css({
'position': 'absolute',
'width': 'auto',
'overflow': 'visible'
});
$(this).after(copyThis);
if(copyThis.width()>$(this).width()){
$(this).html($(this).text().substring(0,leg)+'...');
copyThis.remove();
}else{
copyThis.remove(); //清除复制
return;
}
});
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8706.html