[英]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.