日期:2014-05-17  浏览次数:20391 次

何如在文本框中显示一些特殊的文本?
前台.aspx中有如下代码:

<input type="text" id="sm" value='<%= HttpUtility.HtmlEncode(shuoMing) %>' />

shuoMing是个字符串,里面可能含有单引号或双引号或其他的特殊符号,可能会和value='' 的定界符冲突。

HttpUtility.HtmlEncode确实进行了编码,但没有对引号编码,还有无其他的编码方法???谢谢啦!!!

value='\'' 这样是不行的。

------解决方案--------------------
是对引号进行编码的
方法1
使用双引号
<input type="text" id="sm" value="<%= HttpUtility.HtmlEncode(shuoMing) %>" />

方法2:
<input type="text" id="sm" value='<%= HttpUtility.HtmlEncode(shuoMing).Replace("'","&apos;") %>' />


方法3:
<input type="text" id="sm" value='<%= HttpUtility.HtmlEncode(shuoMing).Replace("'","&#39;") %>' />