首页 > 其他 > 详细

超出文字省略号显示

时间:2015-07-27 14:34:46      阅读:233      评论:0      收藏:0      [点我收藏+]

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>

 

超出文字省略号显示

原文:http://www.cnblogs.com/wenrain/p/4679889.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!