百度空间 | 百度首页 
 
查看文章
 
为什么我的多行文本框里的换行不行呢?
2008-01-30 22:48

在入库之前做一次转换:

HTML标签的转换
<%
Function coder(str)
Dim result,L,i
If IsNull(str) Then : coder="" : Exit Function : End If
L=Len(str) : result=""
For i = 1 to L
select case mid(str,i,1)
case "<" : result=result+"&lt;"
case ">" : result=result+"&gt;"
case "&" : result=result+"&amp;"
case chr(9) : result=result+"&nbsp; &nbsp; "
case chr(13) : result=result+"<br/>"
case chr(32) : result=result+"&nbsp;"
case chr(34) : result=result+"&quot;"
case chr(39) : result=result+"&apos;"
case else : result=result+mid(str,i,1)
end select
Next
coder=result
End Function
%>Top

2 楼Reve(仨仁仕) 回复于 2003-02-16 12:18:24 得分 10

假如你读出来的字符串是str,那么试一下:
Response.Write("<pre>");
Response.Write(str);
Response.Write("</pre>");
Top

3 楼hchxxzx(NET?摸到一点门槛) 回复于 2003-02-16 14:00:11 得分 10

在入库之前做一次转换:???
这种方法尽量不要用,在读取出来时转换就可以了,写进去的时候尽量保持原文的格式是非常重要的。
下面是一个转换的函数
function my_newline(str)
if str<>"" then
my_newline=replace(str,chr(13)&chr(10),"<br>")
my_newline=replace(my_newline,chr(32),"&nbsp;")
my_newline=replace(my_newline,chr(9),"  ")
else
my_newline="&nbsp;"
end if
end function
Top

4 楼ruly(若离) 回复于 2003-02-16 14:58:01 得分 20

一个多文本框里输入东西以后再写进数据库,但是在读出来的时候就没有换行了.这个问题产生的原因是:数据库内存储的是你输入的数据的正确形式,而且当数据从数据库中读出后,写入生成的html代码中时,也是你输入时的形式(这一点你可以通过察看html源文件)。但是当ie解析html文件时就忽略了换行等格式。
解决这个问题有两种方法,就是以上各位提出的“<pre></pre>”格式预先定义标识。还有就是进行编码把格式用html标记描述。Top

相关问题


类别:技术 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu