怎么用ASP控制输出文字的宽度?
比如我想把 10个字控制在 固定的表格里。。多余的自己去掉怎么弄呢? 写个javascript控制一下 :cool: 在适当位置加上:<%if len(trim(rst("newsname")))>16 then
response.write left(trim(rst("newsname")),16)
else
response.write trim(rst("newsname"))
end if
%>
或直接在输出代码加上:<%=left(rs("newsname"),25)&"%>
代码中的16 和25就是要固定输出的字符。要用的话改一下的吧。
不懂的话给我到[url]http://www.2mie.cn[/url]给我留言或在此留言。 <%left(rs("name"),20)%>
20代表20个字符,你可以改成你想要的字数, 多谢 指教。。。
感激ing...感激ing...感激ing....感激ing........
回复 楼主 nanazhutou 的帖子
ASP代码如下:<%if len(trim(rs("title")))>10 then
response.write left(trim(rs("title")),10)
else
response.write trim(rs("title"))
end if%>
或直接在输出代码加上:<%=left(rs("title"),10)&"%>...
这种方式是针对中文的,如果是英文环境的话,那么字节数都要乘以2.即:
<%=left(rs("title"),20)%>...
还有一种方法就是定死表格或者DIV的宽度,这种可以让英文自动换行:
使用样式: word-break : break-all;
[[i] 本帖最后由 sunmuking 于 2008-5-12 21:42 编辑 [/i]] 楼上正解 给你一个函数
调用方法gotTopic(字符串,10)[code]
function gotTopic(str,strlen) 字符串 字符数
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
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
gotTopic=left(str,i) & "…"
exit for
else
gotTopic=str
end if
next
gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
gotTopic=gotTopic
end Function
[/code]
页:
[1]
