<script type="text/javascript">
// 替换特殊字符
function HTMLEncode(text){
text = text.replace(/&/g,
"&") ;
text = text.replace(/"/g,
""") ;
text = text.replace(/</g,
"<") ;
text = text.replace(/>/g,
">") ;
text = text.replace(/‘/g,
"’") ;
text = text.replace(//g," ");
text =
text.replace(/\n/g,"<br>");
text =
text.replace(/\t/g," ");
return text;
}
//还原特殊字符
function TEXTAREAcode(text){
text = text.replace(/\n/g,"");
text = text.replace(/&/g,
"&") ;
text = text.replace(/"/g,
"\"") ;
text = text.replace(/</g,
"<") ;
text = text.replace(/>/g,
">") ;
text = text.replace(/’/g,
"\‘") ;
text = text.replace(/ /g,"
");
text =
text.replace(/<br>/g,"\n");
return text;
}
原文:http://www.cnblogs.com/yangfeizbj/p/3811845.html