首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

何如在文本框中展示一些特殊的文本

2012-10-18 
何如在文本框中显示一些特殊的文本?前台.aspx中有如下代码:input typetext idsm value% HttpUt

何如在文本框中显示一些特殊的文本?
前台.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;") %>' />

热点排行