JS 判断文本是否溢出容器

onShowNameTipsMouseenter: function(e) {
        var target = e.target;
        var containerLength = $(target).width();  //当前容器的宽度
        var textLength = target.scrollWidth;  //当前文字(包括省略部分)的宽度
        var text = $(target).html();
        //console.log("containerLength:" + containerLength);
        //console.log("textLength", textLength);
        if (textLength > containerLength) {
            $(target).attr( "title", text);
        } else {
            $(target).removeAttr( "title");
        }
    }

 

 

 

 

 

 

 

https://www.cnblogs.com/gopark/p/9512290.html

posted @ 2019-07-15 12:16  格鲁特baby  阅读(1180)  评论(0编辑  收藏  举报