js完美解决省略号

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+'...');
            }
    })
};

你可能感兴趣的:(js完美解决省略号)