I'm using JavaScript to pull a value out from a hidden field and display it in a textbox.
(我正在使用JavaScript从隐藏字段中提取值并将其显示在文本框中。)
The value in the hidden field is encoded.(隐藏字段中的值被编码。)
For example,
(例如,)
<input id='hiddenId' type='hidden' value='chalk & cheese' />
gets pulled into
(被拉入)
<input type='text' value='chalk & cheese' />
via some jQuery to get the value from the hidden field (it's at this point that I lose the encoding):
(通过一些jQuery从隐藏字段中获取值(此时我失去了编码):)
$('#hiddenId').attr('value')
The problem is that when I read chalk & cheese
(问题是,当我阅读chalk & cheese
)
chalk & cheese
from the hidden field, JavaScript seems to lose the encoding. (从隐藏字段起, chalk & cheese
似乎失去了编码。)
chalk & cheese
. (我不希望这个价值是chalk & cheese
。)
amp;
(我想要文字amp;
)
(被保留。)
Is there a JavaScript library or a jQuery method that will HTML-encode a string?
(是否有将对字符串进行HTML编码的JavaScript库或jQuery方法?)
ask by AJM translate from so