怎么判断文本内容会超出td?我想实现一个功能,就是在"<td>...文本...</td>"中的文本超出td大小的时候,显示一段文本+"...",然后鼠标移动到td上时显示tip.
可是我怎么才能判断出来文本内容需要的大小超出了td的大小呢?

解决方案 »

  1.   

    判断字符串的长度 当超过一定长度时substring一下 后边加上
    td设置title为完整的字符串试试
      

  2.   

    css
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title> new document </title>
    <style type="text/css">
    .title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 200px;
    }
    </style>
    </head><body>
    <div class="title">
    我想实现一个功能,就是在文本中的文本超出td大小的时候,显示一段文本+"..."
    </div>
    </body>
    </html>
      

  3.   

    学习啦,我也是第一次了解 text-overflow!谢谢学习啦!