[英]Apply ellipsis in table column with different width according to the data in specific column
您只能使用CSS
td{
max-width: 60px; // change as per requirement
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;;
}
在這里查看演示
KooiInc在此問題的答案中提供了一個不錯的JS解決方案。
簡單截斷:
String.prototype.trunc = String.prototype.trunc ||
function(n){
return (this.length > n) ? this.substr(0,n-1)+'…' : this;
};
用法:
var s = 'not very long';
s.trunc(5); //=> not ...
或最后一個字的邊界:
String.prototype.trunc =
function( n, useWordBoundary ){
var isTooLong = this.length > n,
s_ = isTooLong ? this.substr(0,n-1) : this;
s_ = (useWordBoundary && isTooLong) ? s_.substr(0,s_.lastIndexOf(' ')) : s_;
return isTooLong ? s_ + '…' : s_;
};
用法:
var s = 'not very long';
s.trunc(11,true) //=>not very...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.