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>

 

相关文章:

  • 2022-01-02
  • 2022-01-14
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-01-05
  • 2021-12-12
  • 2021-08-06
猜你喜欢
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案