Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jQuery不起作用的情况下追加特殊字符_Javascript_Jquery_Html_Encoding - Fatal编程技术网

Javascript 在jQuery不起作用的情况下追加特殊字符

Javascript 在jQuery不起作用的情况下追加特殊字符,javascript,jquery,html,encoding,Javascript,Jquery,Html,Encoding,我在JavaScript/jQuery中返回特殊字符(特别是°;),但它不会将实体转换为显示中所需的字符。如何正确显示学位标志 它必须简单;我错过了什么?我已经检查了decodeURL,但它什么也没做 HTML: <p>Try to give answer is: </p> <div id="target"></div> <p>But should look like:</p> <div> 5 &

我在JavaScript/jQuery中返回特殊字符(特别是
°;
),但它不会将实体转换为显示中所需的字符。如何正确显示学位标志

它必须简单;我错过了什么?我已经检查了
decodeURL
,但它什么也没做

HTML:

<p>Try to give answer is: </p>
<div id="target"></div>

<p>But should look like:</p>
<div> 5 &deg;C</div>
输出:


要查看解释的字符实体,需要使用
html()

试试这个:

$('#target').html('5 &deg;C');

text
函数将转义
html
字符,这样您就可以看到所看到的内容了。

没问题,很乐意提供帮助。这只是一个简短的说明,供将来参考,它指出了我错误的性质,但最后,我使用了
append
而不是
html
,因为我实际上就是这么做的。
append()
将工作到,因为它不会转义任何字符。我认为
text()
是唯一具有这种行为的jQuery方法
$('#target').html('5 &deg;C');
$('#target').html('5 &deg;C');