Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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中的重音符号和HTML实体_Javascript_Jquery_Json - Fatal编程技术网

Javascript jQuery中的重音符号和HTML实体

Javascript jQuery中的重音符号和HTML实体,javascript,jquery,json,Javascript,Jquery,Json,所以我得到了一个JSON文件(从API中提取),在这里我做了一些比较。我获取JSON文件的内容并将其放在一些按钮上(作为按钮文本)。然后,我对按钮文本和JSON文件中的文本之间的相等性进行了比较测试 这在我99%的用例中都有效,但是: 我的JSON文件中的一些单词带有重音符号(或者是,等等)。当我尝试在jQuery中进行比较时,即使我使用的是: $(this).html() 对于我的按钮文本,相等性测试失败。JSON文件中的单词可能为: Fréd&ea

所以我得到了一个JSON文件(从API中提取),在这里我做了一些比较。我获取JSON文件的内容并将其放在一些按钮上(作为按钮文本)。然后,我对按钮文本和JSON文件中的文本之间的相等性进行了比较测试

这在我99%的用例中都有效,但是:

我的JSON文件中的一些单词带有重音符号(或者是,等等)。当我尝试在jQuery中进行比较时,即使我使用的是:

   $(this).html()
对于我的按钮文本,相等性测试失败。JSON文件中的单词可能为:

   Frédéric Auguste Bartholdi 
但我的按钮上写着:

    Frédéric Auguste Bartholdi
我想如果我做一个比较测试,比如:

    if($(this).html() === jsonFile[0])){...}
这会起作用,但似乎不行。为了清楚起见(这)指的是我的按钮,我对JSON文件真的做不了太多——无法更改

有人有什么想法吗?

不要使用$(this).html()而使用$(this).text()。因为.html()-将返回这些Unicode的html格式。

很容易:

function html_entities(str){
    return $('<textarea />').html(str).text();
}
$('div').text(html_entities("Fr&eacute;d&eacute;ric Auguste Bartholdi"));
函数html\u实体(str){
返回$('').html(str.text();
}
$('div').text(html_实体(“Fré;dé;ric Auguste Bartholdi”);
见:

感谢:

您应该尝试
$(this).text()
而不是
$(this).html()

请参阅。在进行比较之前,您需要将重音字符替换为英语对应字符。可能是这样吗?