zoukankan      html  css  js  c++  java
  • html 长文本 截断 jquery 扩展脚本

    (function ($)
    {
        $.LongTextFormat = function (selector, fmlength)
        {
            var re = /\s/g;
            $(selector).each(function (i)
            {
                //获取td当前对象的文本,如果长度大于25; 
                var jobj = $(this);
                var text = jobj.text();
                if (text)
                {
                    text = text.replace(re, "");
                    if (text.length > fmlength)
                    {
                        //给td设置title属性,并且设置td的完整值.给title属性.  
                        var oldTitle = jobj.attr("title");
                        jobj.attr("title", oldTitle + "  " + text);
                        //获取td的值,进行截取。赋值给text变量保存.  
                        var ntext = text.substring(0, 25) + "...";
                        //重新为td赋值;  
                        jobj.text(ntext);
                    }
                }
            });
        };    
    })(jQuery);

    调用:

    $.LongTextFormat(".fmtable tr td", 18);

    jquery 自动截断 过长文本

  • 相关阅读:
    GPS 经纬度
    TP5 分页数据加锚点
    修改layui的表单手机、邮箱验证可以为空怎么实现?
    转录调控实战 | 一文解决转录调控问题 | chIP-seq | ATAC-seq
    管家基因 | Human housekeeping genes
    各国脑计划概览
    原创
    RLE Plots: relative log expression
    Polygenic score
    皮尔逊残差 | Pearson residual
  • 原文地址:https://www.cnblogs.com/yelaiju/p/2770404.html
Copyright © 2011-2022 走看看