js Html構造を文字列に変換して表示します.

1375 ワード

    //Html             <br>  

    function ToHtmlString(htmlStr) {

        return toTXT(htmlStr).replace(/\&lt\;br[\&ensp\;|\&emsp\;]*[\/]?\&gt\;|\r
|
/g, "<br/>"); } //Html function toTXT(str) { var RexStr = /\<|\>|\"|\'|\&| | /g str = str.replace(RexStr, function (MatchStr) { switch (MatchStr) { case "<": return "&lt;"; break; case ">": return "&gt;"; break; case "\"": return "&quot;"; break; case "'": return "&#39;"; break; case "&": return "&amp;"; break; case " ": return "&ensp;"; break; case " ": return "&emsp;"; break; default: break; } } ) return str; }