string 转 html js textarea text 转div

来源:互联网 发布:ntfs for mac如何用 编辑:程序博客网 时间:2024/05/28 11:28

   String.prototype.replaceAll = function(s1,s2){ 
return this.replace(new RegExp(s1,"gm"),s2); 

var textTohtml = function( $str ){

    return $str.replaceAll("&", "&")
    .replaceAll("<", "&lt;")
    .replaceAll(">", "&gt;")
    .replaceAll(String.fromCharCode(32), "&nbsp;")
    .replaceAll(String.fromCharCode(9), "&nbsp;")
    .replaceAll(String.fromCharCode(9), "&#160;&#160;&#160;&#160;")
    .replaceAll(String.fromCharCode(34),  "&quot;")
    .replaceAll(String.fromCharCode(39),  "&#39;")
    .replaceAll(String.fromCharCode(13),  "")
    .replaceAll(String.fromCharCode(10),  "<br/>")
    }
0 0