ASP代码限制首页链接新闻标题字数为10,剩下的为省略号。试过加left 可是不知道为什么不可以。求解
<%Response.Write("<divclass='banner'align='center'><imgsrc="&Lelogo&"/></div>")dimrs,...
<%
Response.Write("<div class='banner' align='center' ><img src="&Lelogo&" /></div>")
dim rs,sql
set rs = server.createobject("adodb.recordset")
sql="select * from zhi_rui_v_Navigation where ViewFlag=1 order by Sequence asc"
rs.open sql,conn,1,1
response.Write("<div id=menu_out><div id=menu_in><div id=""menu""><ul id=""topnav"">")
if rs.bof and rs.eof then
response.write "<li>暂无导航链接</li>"
else
do
response.write "<li><a href='"&rs("NavUrl")&"'target='_blank'>"&rs("NavName")&"</a></li>"
rs.movenext
loop until rs.eof
response.Write("</ul></div></div></div>")
rs.close
set rs=nothing
%> 展开
Response.Write("<div class='banner' align='center' ><img src="&Lelogo&" /></div>")
dim rs,sql
set rs = server.createobject("adodb.recordset")
sql="select * from zhi_rui_v_Navigation where ViewFlag=1 order by Sequence asc"
rs.open sql,conn,1,1
response.Write("<div id=menu_out><div id=menu_in><div id=""menu""><ul id=""topnav"">")
if rs.bof and rs.eof then
response.write "<li>暂无导航链接</li>"
else
do
response.write "<li><a href='"&rs("NavUrl")&"'target='_blank'>"&rs("NavName")&"</a></li>"
rs.movenext
loop until rs.eof
response.Write("</ul></div></div></div>")
rs.close
set rs=nothing
%> 展开
展开全部
'**************************************************
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
Function gotTopic(ByVal str, ByVal strlen)
If str = "" Then
gotTopic = ""
Exit Function
End If
Dim l, t, c, i, strTemp
str = Replace(Replace(Replace(Replace(str, " ", " "), "", Chr(34)), ">", ">"), "<", "<")
l = Len(str)
t = 0
strTemp = str
strlen = CLng(strlen)
For i = 1 To l
c = Abs(Asc(Mid(str, i, 1)))
If c > 255 Then
t = t + 2
Else
t = t + 1
End If
If t >= strlen Then
strTemp = Left(str, i)
Exit For
End If
Next
If strTemp <> str Then
strTemp = strTemp & "…"
End If
gotTopic = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), ""), ">", ">"), "<", "<")
End Function
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
Function gotTopic(ByVal str, ByVal strlen)
If str = "" Then
gotTopic = ""
Exit Function
End If
Dim l, t, c, i, strTemp
str = Replace(Replace(Replace(Replace(str, " ", " "), "", Chr(34)), ">", ">"), "<", "<")
l = Len(str)
t = 0
strTemp = str
strlen = CLng(strlen)
For i = 1 To l
c = Abs(Asc(Mid(str, i, 1)))
If c > 255 Then
t = t + 2
Else
t = t + 1
End If
If t >= strlen Then
strTemp = Left(str, i)
Exit For
End If
Next
If strTemp <> str Then
strTemp = strTemp & "…"
End If
gotTopic = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), ""), ">", ">"), "<", "<")
End Function
展开全部
最简单的是left(rs("NavName"),20),这样就是截取20个字符
要更智能一下,可以写一个函数,判断一下英文数字和汉字,因为汉字占两个字节,另外还可以判断一下是否显示...
要更智能一下,可以写一个函数,判断一下英文数字和汉字,因为汉字占两个字节,另外还可以判断一下是否显示...
更多追问追答
追问
加在哪里?response.write ""&left(rs("NavName"),20)&"" 这样吗?可是测试了不行,在首页新闻里面效果没变
追答
left(rs("NavName"),20)改成left(rs("NavName"),2) 看是不是有效,如果标题本身没超出20个字符是没效果呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询