程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> 將多行區域表單中的內容換成html代碼

將多行區域表單中的內容換成html代碼

編輯:ASP技巧
開始將多行區域表單中的內容沒有處理,就直接保存起來,然後在顯示的時候發現,明明保存的時候有換行等格式,但是顯示不出來,所有的內容都在一行上。原因是沒有將多行區域表單中的內容換成Html格式引起這個原因的。 01 '字符串內容Html化 02 Function inHtml(str) 03     Dim sTemp 04     sTemp = str 05     inHtml = "" 06     If IsNull(sTemp) = True Then 07         Exit Function 08     End If 09     'stemp=Replace(stemp, CHR(38), "&#38;") 10     sTemp = Replace(sTemp, "&""&amp;") 11     sTemp = Replace(sTemp, "<""&lt;") 12     sTemp = Replace(sTemp, ">""&gt;") 13     stemp=Replace(stemp, CHR(39), "&#39;") 14     stemp= Replace(stemp, CHR(32), "&nbsp;") 15     sTemp = Replace(sTemp, Chr(34), "&quot;") 16     stemp = Replace(stemp, CHR(13), """") 17     stemp = Replace(stemp, CHR(10), "<br>") 18     inHtml = sTemp 19 End Function 20   21 '將Html字符化 22 Function outHtml(str) 23     Dim sTemp 24     sTemp = str 25     outHtml = "" 26     If IsNull(sTemp) = True Then 27         Exit Function 28     End If  29     stemp=replace(stemp,"<br>",chr(10)) 30     stemp=replace(stemp,"""",chr(13)) 31     stemp=replace(stemp,"&quot;",chr(34)) 32     stemp=replace(stemp,"&nbsp;",chr(32)) 33     stemp=replace(stemp,"&#39;",chr(39)) 34     stemp=replace(stemp,"&gt;",">") 35     stemp=replace(stemp,"&lt;","<") 36     stemp=replace(stemp,"&amp;","&") 37     'stemp=replace(stemp,"&#38;",chr(38)) 38     outHtml = sTemp 39 End Function(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)

用法:
 text=inhtml(request("textarea"))'這樣就將textarea中的內容轉換成了Html代碼
 當顯示數據庫中這個內容到多行表單方法
 <textarea name="textarea" cols="30" rows="30"><%=outHtml(rs("字段名"))%>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved