截字符串加省略号

工作繁忙,手指在键盘上翻飞,闪出时间把刚写的截字符串的代码粘贴过来,这是太常用的方法了

  
    
$( function (){
$(
' .fn_sliceStr ' ).each( function (){
var len = parseFloat($( this ).attr( ' name ' ));
var str = $( this ).text();
if (str.length > len){
$(
this ).text(str.slice( 0 ,len) + ' ... ' );
}
});
});

你可能感兴趣的:(字符串)