标签:style blog class code java ext javascript width color strong int
例如 将 & 翻译为
<input value="<%=encodeHTML(name)%>">
==>
<input value=" "> <!-- 控件值显示为 一个 & -->
例如 将 " 翻译为 \"
var name = “<%=name%>”;
==>
var name = "\"";
字符 |
转义字符 |
描述 |
& |
& |
和 |
< |
< |
小于号 |
> |
> |
大于号 |
" |
" |
双引号 |
‘ |
' |
单引号 |
<html> <head> <script type="text/javascript" src="./jquery/jquery-1.9.1.js"></script> </head> <body> <div id="test"></div> <div id="test1"></div> <input type="text" id="inputText"> <script> $("#test").text("<div>aa<</div>") $("#test1").html($("#test").html() + "<div>OOOOO</div>") $("#inputText").val($("#test").html()); </script> </body> </html>
var decoded = $("<div/>").html(encodedStr).text();
<html> <head> <script type="text/javascript" src="./jquery/jquery-1.9.1.js"></script> </head> <body> <div id="test"></div> <input type="text" id="inputText"> <script> $("#test").html("<<div>f</div>") $("#inputText").val($("#test").html()); //html arg $("#inputText").val($("#test").text()); // text in html DOM </script> </body> </html>
<script 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; } var html = “<br>dffdfqqqqq”; var encodeHTML = HTMLEncode(html); alert(“方法一:” +encodeHTML); var decodeHTML = HTMLDecode(encodeHTML); alert(“方法一:” +decodeHTML); </script>
标签:style blog class code java ext javascript width color strong int
原文地址:http://www.cnblogs.com/lightsong/p/3702612.html