<table border=1 width=100><tr><td>
<div nowrap style="width:100; overflow:hidden">这里就是你想要显示的内容</div></td></tr></table>
<div nowrap style="width:100; overflow:hidden">这里就是你想要显示的内容</div></td></tr></table>
调试欢乐多
<tr>
<td width="12" height="52" id= t1> </td>
<td width="102" height="52"> </td>
<td width="143" height="52"> </td>
</tr>
</table>
<input type = button value = sub onclick=sub()><script>
function sub()
{ var str= '1111111111112222222222222222222222222222222333333333333333333333334444444444444444444445555555555';
if (str.length>5)
{
t1.innerText = str.substr(1,5)+'...';
}
}
</script>
各位帮帮忙,看有什么好方法。
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="386" height="163" id="AutoNumber1">
<tr>
<td width="12" height="52" id= t1> </td>
<td width="102" height="52"> </td>
<td width="143" height="52"> </td>
</tr>
</table>
<input type = button value = sub onclick=sub()><script>
function sub()
{ var str= '1111111111112222222222222222222222222222222333333333333333333333334444444444444444444445555555555';
if (str.length>5)
{
t1.innerText = str.substr(1,5)+'...';
}
}
</script>
----------------------
上面程序唯一的不足就是6个英文与6个汉字都会同样处理,但6个英文明显比5个汉字短.
可以用下面的程序:
<td width=50 id=t1>111了在工在发厅ABCDD<td>
<td width=50 id=t2>abc<td>
<script>function f1()
{
iWidth=parseInt(t1.width) while(t1.clientWidth>iWidth)//clientWidth为TD的实际宽度,width为TD定义的宽度,不会跟着TD变宽的
{
t1.innerText=t1.innerText.substr(0,t1.innerText.length-4)+"..."
}}
</script>
width: 120px; height: 50px; border: 1px solid blue;
font: 14px Times New Roman, serif; overflow: hidden;
text-overflow:ellipsis">
<nobr>在指定列宽asdfasdfsdd的表格中显示字符串,如果一列的宽度不足以显示所有的字符,而客户</nobr>
</DIV>