怎么让新闻再首页上显示几个字

来源:百度知道 编辑:UC知道 时间:2024/06/03 15:50:34
这是新闻页面
我准备把它嵌入到主页上去,怎么能让新闻不显示全部的标题名字,而是根据宽度自己变化!
<TABLE cellSpacing=0 cellPadding=0 width="209" border=0 style="border-collapse: collapse" bordercolor="#111111">
<TBODY>
<TR vAlign=top>
<TD width="209"><TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>

<TR>
<TD vAlign=top align=middle><table cellspacing=0 cellpadding=0 width="96%" border=0 align="center">
<%
set rs=server.createobject("adodb.recordset")
sql="select * from FeiNews order by id desc"
rs.open sql,conn,1,1
if rs.eof then
response.Write"<tr><td class=""reg3""><li>暂没有新闻!</td></tr>"
else
i=1
rs.Pagesize=20
Pagesize=rs.Pagesize
Allrecord=rs.Recordcount
Allpage=

可以用一个函数来判断Title的字符串长度,设置一个你的表格宽度大概能装下的文字长度,设为maxLength。Title的长度小于maxLength,则让Title内容显示完,否则取Title的0至maxLength字符,后面的加省略号即可

你用的是asp,我会点jsp,那用jsp写一下,设置显示最大字符串为20
<%String Title = rs.getString("Title");%>
<td width="44%" class="reg3"><a href=News.jsp?Seo=<%=rs.getInt("ID")> target=blank><%=Title.length()<20?Title:Title.substring(0,20)+"..."%></a></td>

但愿说明白了:)

设下格子的宽度