我希望有人通知我,如何实现JavaScriptStringEncode()
功能以及用于什么?
答案 0 :(得分:2)
你可以这样做
<script>
// wrap in quotes automatically
alert(<%=HttpUtility.JavaScriptStringEncode(MyStringHere, true)%>);
// add quotes manually
alert("<%=HttpUtility.JavaScriptStringEncode(MyStringHere)%>");
alert("<%=HttpUtility.JavaScriptStringEncode(MyStringHere, false)%>");
</script>
HttpUtility.JavaScriptStringEncode()方法将html内容转换为兼容javascript。
答案 1 :(得分:0)
“此方法对字符串进行编码。例如,单引号和双引号在编码字符串中包含为\'和\”。
URL编码可确保所有浏览器都正确地在URL字符串中传输文本。某些浏览器可能会截断或损坏诸如问号(?),&符号,斜杠(/)和空格等字符。因此,这些字符必须编码在元素或查询字符串中,其中字符串可以由浏览器在请求字符串中重新发送。“