javascript编程的组件
源代码在线查看: 保持文本格式的两种方法.htm
保持文本格式的两种方法
width="90%" borderColorLight=#000000 border=1>
保持文本格式的两种方法
1.<script language=javascript>function
coder(str){var s = "";if (str.length == 0) return "";for
(var i=0; i<str.length; i++){switch
(str.substr(i,1)){case "<" : s += "<"; break;case
">" : s += ">"; break;case "&" : s += "&";
break;case " " : s += " "; break;case "\'" : s +=
"'"; break;case "\"" : s += """; break;case "\n"
: s += "<br>"; break;default : s += str.substr(i,1);
break;}}return s;}2.<%Function
coder(str)Dim result,L,iIf IsNull(str) Then : coder="" : Exit
Function : End IfL=Len(str) : result=""For i = 1 to Lselect
case mid(str,i,1)case "<" : result=result+"<"case ">"
: result=result+">"case chr(34) :
result=result+"""case "&" :
result=result+"&"case chr(13) :
result=result+"<br/>"case chr(9) : result=result+"
"case chr(32) : result=result+" "case else :
result=result+mid(str,i,1)end selectNextcoder=resultEnd
Function %>
【阿信的小天地】