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