js判断文本是否溢出容器


onShowNameTipsMouseenter: function(e) {
        var target = e.target;
        var containerLength = $(target).width();
        var textLength = target.scrollWidth;
        var text = $(target).html();
        //console.log("contentLength:" + containerLength);
        //console.log("textLength", textLength);
        if (textLength > containerLength) {
            $(target).attr( "title", text);
        } else {
            $(target).removeAttr( "title");
        }
    }

var containerLength = $(target).width(); 当前容器的宽度
var textLength = target.scrollWidth; 当前文字(包括省略部分)的宽度


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM