落伍者站长论坛's Archiver

nanazhutou 发表于 2008-5-8 17:57

怎么用ASP控制输出文字的宽度?

比如我想把 10个字控制在 固定的表格里。。多余的自己去掉
怎么弄呢?

zaybajlhqwb 发表于 2008-5-8 21:06

写个javascript控制一下

ebook 发表于 2008-5-8 23:50

:cool:

mmxkn2007 发表于 2008-5-8 23:56

在适当位置加上:<%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]给我留言或在此留言。

dahaisky 发表于 2008-5-9 19:34

<%left(rs("name"),20)%>
20代表20个字符,你可以改成你想要的字数,

nanazhutou 发表于 2008-5-12 17:00

多谢 指教。。。

感激ing...感激ing...感激ing....感激ing........

sunmuking 发表于 2008-5-12 17:29

回复 楼主 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]]

measi 发表于 2008-5-12 17:54

楼上正解

jesses 发表于 2008-5-12 22:57

给你一个函数

调用方法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,"&nbsp;"," "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")
        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," ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")
        gotTopic=gotTopic
end Function
[/code]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.