文字超过字符长度 显示… 点点点 jquery

在 script脚本区域里面定义如下方法

jQuery.fn.limit = function() {
            var self = $("[limit]");
            self.each(function() {
                var objString = $(this).text();
                var objLength = $(this).text().length;
                var num = $(this).attr("limit");
                if (objLength > num) {
                    $(this).attr("title", objString);
                    objString = $(this).text(objString.substring(0, num) + "...");
                }
            });
        };

然后在 $(function(){

})  里面  加入下面的文字


$("#span_username").attr("limit", 5); //对哪些进行截取(实际就是给元素添加了limit属性,值是5)
$("#span_schoolname").attr("limit", 10);
$("[limit]").limit(); //这个要有,表示执行 截取
原文地址:https://www.cnblogs.com/joeylee/p/3730526.html