js完美解决省略号

2017-12-21  本文已影响0人  多多VS串串
function ctrlSign() {
      // *= 所选元素
    $('*').each(
        function(){
            var _this = $(this);
            var txt = _this.text(), 
            w = _this.width(),
            fs =parseInt(_this.css('fontSize'));
            n = parseInt(w/fs)*2 - 1;
            if(txt.length >= n){
                ntxt = txt.slice(0,n);
                _this.text(ntxt+'...');
            }
    })
};
上一篇 下一篇

猜你喜欢

热点阅读