剪切文本
问题描述:
<table id="tab">
<tr><td class="sub">mmmmm</td><td class="sub">jjjjj</td></tr>
<tr><td class="sub">lllll</td><td class="sub">wwwww</td></tr>
</table>
#tab td {
border: 1px solid green;
max-width: 40px;
}
$(".sub").each(function(){
var o = $(this).html();
$(this).html(o.substring(0, 2))
})
活生生的例子:http://jsfiddle.net/UTYLf/1/剪切文本
我想最大宽度为TD - 40像素。我想剪切溢出文本。我做了子串,但这不是有用的。 毫米!= LL和JJ!= WW等毫米和LL有2个字符,但毫米需要更多的空间比一个LL。 在我的例子中,我想在表中与本例中的相同:http://jsfiddle.net/Eb6WN/
我必须用什么来代替substr? 我可以使用HTML,CSS,JavaScript的(jQuery的)和PHP
答
在这些类型的我用overflow: hidden
情况以及加入title
每个单元格中显示完整的文本:
#tab td {
border: 1px solid green;
max-width: 40px;
overflow: hidden;
}
$(".sub").each(function(){
$(this).attr("title", $(this).text()).css("cursor", "help");
})
答
你为什么不使用overflow: hidden;
这个?
答
你可以尝试添加text-overflow
属性,你的第一个CSS类。
#tab td {
border: 1px solid green;
max-width: 40px;
text-overflow: ellipsis;
}
有些文档约text-overflow
可以发现here。
+1
一些更好的非W3S文档[可在此处找到](http://www.quirksmode.org/ CSS/textoverflow.html)。 [对W3Schools说不。](http://www.w3fools.com/)。 – DaveRandom
你想'溢出:hidden'到'td's? – pimvdb
您可以“隐藏”溢出文本,例如:http://jsfiddle.net/Eb6WN/3/ – SERPRO