我正在使用JavaScript从隐藏字段中提取值并将其显示在文本框中.隐藏字段中的值已编码.
例如,
<input id='hiddenId' type='hidden' value='chalk & cheese' />
Run Code Online (Sandbox Code Playgroud)
被拉进去
<input type='text' value='chalk & cheese' />
Run Code Online (Sandbox Code Playgroud)
通过一些jQuery从隐藏字段中获取值(此时我丢失了编码):
$('#hiddenId').attr('value')
Run Code Online (Sandbox Code Playgroud)
问题是,当我chalk & cheese
从隐藏字段中读取时,JavaScript似乎失去了编码.为了逃避chalk & cheese
和amp;
,我想编码保留.
是否有一个JavaScript库或jQuery方法将对字符串进行HTML编码?
任何人都知道我为什么会收到以下错误?我启用了调试功能.
Server Error in '/' Application.
--------------------------------------------------------------------------------
A potentially dangerous Request.Form value was detected from the client (strContent="<p>
test</p>
").
Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended …
Run Code Online (Sandbox Code Playgroud)