试试<td width="150">然后根据字体大小计算150px显示多少字符包括汉字,再在显示时只显示固定的字符。

解决方案 »

  1.   

    在TD里加入这句:
    <td width=150 height=20>
    <div style="width: 150; overflow: hidden"><%=rs("txt")%></div>
    </td>
      

  2.   

    如果动态截掉的话,字段值的长度不定,如果只保留30字符,但有的字段值为空或者只有一两个字符怎么办?截取时会出现错误。不知道有没有一个统一的方法来截取?我用JSP,谢谢!
      

  3.   

    <%
    String test=rs.getString("test");
    if(test!=null&&test.length>30)
       test=test.substring(0,30);
    out.println(test);
    %>但是你这样凭空截掉,有头无尾,用户怎么看呀,是不是应该在不全的文字后面加上省略号,并提供一个链接,允许用户看到完整的信息
      

  4.   

    心宇你的方法不错哟!THANKS!送分!
      

  5.   

    '限定显示字符串长度
    function FixStrHTML(strString,intLen)
        dim strS, strT
        dim realLen
        if len(strString)>realLen then
            strS = FixStr(strString,realLen-3) & "..."
            strT = strString
        else
            strS = strString
            strT = ""
        end if
        FixStrHTML = "<nobr><span title='" & strT & "'>" & strS & "</span></nobr>"
    end function'把一串字符串(包含中文)截断
    Function FixStr(strSource, intLen)
        Dim idx 
        Dim intL
        intL = 0
        For idx = 1 To Len(strSource)
            if AscW(Mid(strSource, idx, 1)) > 256 then
                intL = intL + 2
            Else
                intL = intL + 1
            End If
            If intL > intLen Then
                idx = idx - 1
                Exit For
            ElseIf intL = intLen Then
                Exit For
            End If
        Next
        FixStr = Left(strSource, idx)
    End Function