我需要保留传递给 .html()
的每个字符按原样,即未编码。例如,.html('>')
将小于号保存为 >
,不是<
。我该怎么做?理想情况下,该解决方案将应用于所有“特殊”字符,例如<
, &
等
<h1 id="my-title"></h1>
// JavaScript / jQuery code.
$('#my-title').html('>');
...
...
// Somewhere else in the code, I need to retrieve the value back by calling
// var v = $('#my-title').html();
最佳答案
使用text()
代替html()
var v = $('#my-title').text();
关于jquery - .html() 不对传递的值进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9350441/