超长文本Table的处理
浏览(1757)添加样式
.table-ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-wrap: normal;
}
$.tableTextLong = function (table) { var $table = $(table); var $th = $table.find("th"); var targetWidth = $table.width() / ($th.length-2); //判断是否有checkbox的列 if ($table.find('th.select-checkbox').length > 0) { $table.find('th.select-checkbox').css("width", "50px"); } //判断 $th.each(function (idx, obj) { if ($(obj).width() > targetWidth) { var $tr = $table.find('tr'); for (var i = 0; i < $tr.length; i++) { var $td = $($tr[i]).find('td').eq(idx); if ($td.children("a,button").hasClass("btn")) { break; } var $div = $("
").addClass("table-ellipsis").prop("title", $td.text()).append($td.html()).css("max-width", targetWidth); $td.empty().append($div).css("width", targetWidth); } } }); };
标签: