超出文字省略号显示

css方法:

overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;

js方法:

function Ellipsis() {
    $(".overflowHidden").each(function(){
        maxwidth=$(this).attr("data-max");
    if($(this).text().length>maxwidth){
        $(this).text($(this).text().substring(0,maxwidth));
        $(this).html($(this).html()+'...');
    }else{
        $(this).text($(this).text());
    }
    });
}
html页面中使用的时候:
<div class="overflowHidden" data-max="10" >
</div>
<script>
  
Ellipsis();
//调用函数;
</script>
原文地址:https://www.cnblogs.com/wenrain/p/4679889.html