JS中 HTMLEncode和HTMLDecode


<!--js偽編碼解碼-->
<script language="javascript" type="text/javascript">
function HTMLEncode(html)
{
var temp = document.createElement ("div");
(temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
var output = temp.innerHTML;
temp = null;
return output;
}
function HTMLDecode(text)
{
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
}
</script>

JS 中並非 C#中的Server.HtmlDecode Server.HTMLEncode 他並非真的編碼解碼 而是偽裝:把你要寫入的內容放入它自己創建的DIV 中,

例:

$("wordDescription").innerText=HTMLDecode(HTMLDecode(JianJie.toString()));

本人用的是:span

<span id="wordDescription" style="vertical-align:top;"> </span>

////////////////后台:

//string JianJie = Server.HtmlDecode(ds.Tables[0].Rows[0]["gagahjt"].ToString()).ToString();//如在后台html解碼 前台需要一個HTMLDecode,否則需要2個HTMLDecode
string JianJie = ds.Tables[0].Rows[0]["gagahjt"].ToString();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM