js轉譯html標籤

api返回的接口數據是這樣的"<div>測試數據</div>"html

js拼接html時會過濾掉<div></div>api

因此須要對<div></div> 進行轉譯函數

以下函數測試

1     function html2Escape(sHtml) {
2         return sHtml.replace(/[<>&"]/g, function (c) { return { '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' }[c]; });
3     }
相關文章
相關標籤/搜索