首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp中新闻标题省略的有关问题

2012-02-06 
asp中新闻标题省略的问题我做了一个公告可是标题显示太长了我想让太长的标题只显示前面几个字符后面的用省

asp中新闻标题省略的问题
我做了一个公告   可是标题显示太长了我想让太长的标题只显示前面几个字符后面的用省略号   而且鼠标放在上面能显示全部!   那位大哥能帮我一下   公告代码如下

  <td   width= "169 "   background= "img/b4.GIF "   height= "35 "> 网站公告 </td>
        <td>
    <MARQUEE   id=scrolltext     onMouseOver=this.stop()   onMouseOut=this.start()   scrollAmount=1   scrollDelay=30   direction=up   width=176   height=130   name= "scrolltext ">  
    <%   exec= "SELECT   top   3   *   FROM   gg   order   by   id   DESC "      
set   rs=server.createobject( "adodb.recordset ")
rs.open   exec,conn,1,1
  Response.Write   " <div   align= " "left " "> "   &   vbCrLf
      Response.Write   " <table   border= " "0 " "   cellpadding= " "0 " "   cellspacing= " "1 " "   height= " "160 " "   width= " "194 " "> "   &   vbCrLf
        do   while   not   rs.eof
    Response.Write   " <tr> "   &   vbCrLf
        if   len(ggbt)> 12   then
Response.Write   " <td   class=tl> &nbsp;. "&rs( "ggbt ")&rs(ggbt,17)& "&nbsp; </td> "   &   vbCrLf
else
Response.Write   " <td   class=tl> &nbsp;. "&rs( "ggbt ")& "&nbsp; </td> "   &   vbCrLf
end   if
  Response.Write   " </tr> "   &   vbCrLf
    rs.movenext
loop
if     rs.eof   and     rs.bof   then
Response.Write   " <font   color= " "#666666 " "> 目前尚无任何公告! </font> "
end   if
Response.Write   " </table> "   &   vbCrLf
Response.Write   " </div> "   &   vbCrLf
%>
</td>
</marquee>


[解决办法]
输出的标题用left函数截取字符,比如,要截取字符串str的前50个字符,并且鼠标移到连接上,显示所有的str字符,就使用下面的代码
<a href= "index.aspx?id=.... " title= " <%=str%> "> <%=left(str,50)%> </a>
[解决办法]


输出的标题用left函数截取字符,比如,要截取字符串str的前50个字符,并且鼠标移到连接上,显示所有的str字符,就使用下面的代码
<a href= "index.aspx?id=.... " title= " <%=str%> "> <%=left(str,50)%> </a>

[解决办法]
中英文混合的截字符串截取函数

Function CountLength(Str)
Dim output,ThisChar,i
output = 0
For i = 1 To Len(Str)
ThisChar = Mid(Str,i,1)
If Asc(ThisChar) < 0 Then
output = output + 2
Else
output = output + 1
End If
Next
CountLength = output
End Function

Function MaxLengthStr(ByVal Str, ByVal MaxLength)
Dim Output,i
If IsNull(Str) Then Str = " "
Output = " "
If LenB(Str) <= MaxLength Then
Output = Str
Else
For i = 1 To Len(Str)
Output = Output & Mid(Str,i,1)
If CountLength(Output)+3 = MaxLength Then
Output = Output & "... "


Exit For
ElseIf CountLength(Output)+3 > MaxLength Then
Output = Left(Output,Len(Output)-1) & "... "
Exit For
End If
Next
End If
MaxLengthStr = Output
End Function

Response.Write MaxLengthStr( "One World One Dream,北京2008 ", 25)

Response.Write MaxLengthStr( "北京2008,One World One Dream,北京2008 ", 25)


[解决办法]
<a href= "index.aspx?id=.... " title= " <%=str%> "> <%=left(str,50)%> </a>
[解决办法]
高效代码,不是整篇替换,而是根据你定义的长度直接截取,到达指定字符就不再替换,可以减轻服务器负担。
Function CutStr(str,strlen,endStr)
If str= " " Or strlen=0 Then Exit Function
Dim i,IsNeed,CurLen,TempStr,TempStr1
For i=0 To Len(str)-1
TempStr1=Mid(str,i+1,1)
If TempStr1= " < " Then
IsNeed=1
Else
If IsNeed=0 Then
TempStr=TempStr&TempStr1
If Abs(Asc(TempStr1))> 255 Then
CurLen=CurLen+2
Else
CurLen=CurLen+1
End If
End If
If CurLen> =strlen Then Exit For
If TempStr1= "> " Then IsNeed=0
End If
Next
If strlen> =Len(str) Then endStr= " "
CutStr=TempStr&endStr
End function
[解决办法]
简单的做法:
if len(rs( "file "))> 10 then
str=left(rs( "file "),10)& "... " '取前面10个字加省略号.
end if

<a href= "s.asp?id= <%=rs( "id ")%> " title= <%=rs( "file ")%> > str </a>

热点排行