• HTML中文本过长时自动隐藏末尾部分或中间等任意部分


    一、
        一般情况下,HTML字符串过长时都会将超过的部分隐藏点,方法如下:

          设置CSS:

                .ellipsis-type{

    max- 50px;                      //显示宽度
    white-space: nowrap;                //文本不换行。
    overflow: hidden;                       //超过部分隐藏

    text-overflow: ellipsis;                //超过部分用...代替

                     cursor: pointer;                         //鼠标设置(不是必须)

    }

        如果要查看整个字符串,可以引用popover

              <script src="/static/common/js/popover.js"></script>

        <tr class='file_name'>

        <td class="ellipsis" data-toggle="popover" data-content="{{ your value}}" data-placement="bottom" data-container="body" >your text</td>

        </tr>

    二、
        上面是通过CSS隐藏末端字符串。如果末端字符串有参考价值,可以通过js将字串中间或前部用特定字符代替。

        $(".file_name").each(function(){                                                               //遍历file_name中的每个子元素
            var v = $(this).children('.ellipsis').text();
            if (v.length > 50)

    {

                                // 用V的前20个字符+"......"+后15个字符代替V

        var new_value = v.substring(0,20)+'......'+v.substring(v.length-15,v.length);
    $(this).children('.name').text(new_value); //设置新的text()
    }
    });
    ---------------------
    作者:carrey_0612
    来源:CSDN
    原文:https://blog.csdn.net/carrey_0612/article/details/80654960
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    GridView编辑删除取消完整代码
    添加删除组件里没有IIS
    关于网站开发中存在的问题
    网络公司网站源码介绍Version1.0
    IIS 状态代码
    收藏常用的快捷方式
    连接池已经满的解决方案
    Do you choose a experienced employee with highsalary or a inexperienced employee with lowsalary?
    Registered Permanent residence/attitude for sports
    数据缓存依赖
  • 原文地址:https://www.cnblogs.com/yanglang/p/9883902.html
Copyright © 2020-2023  润新知