Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.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将HTML代码转换为普通文本?_Javascript_Html_Json_Ascii - Fatal编程技术网

如何使用javascript将HTML代码转换为普通文本?

如何使用javascript将HTML代码转换为普通文本?,javascript,html,json,ascii,Javascript,Html,Json,Ascii,我想从这样的API转换输入 <p>Communication that doesn&#8217;t take a chance doesn&#8217;t stand a chance.</p> 不需要’;不要冒险;我没有机会 像这样的事情 “不冒险的交流是没有机会的。” 我知道html可以翻译它,但我不知道如何直接翻译它以便在javascript中使用,将其作为html插入元素,并将其作为文本读回 var elt = documen

我想从这样的API转换输入

    <p>Communication that doesn&#8217;t take a chance doesn&#8217;t stand a chance.</p>
不需要’;不要冒险;我没有机会

像这样的事情 “不冒险的交流是没有机会的。”


我知道html可以翻译它,但我不知道如何直接翻译它以便在javascript中使用,将其作为html插入元素,并将其作为文本读回

var elt = document.createElement('div');
elt.innerHTML = apiResponse;
alert(elt.textContent);

@“MikeC,但这是用jquery回答的。”RajaprabhuAravindasamy进一步阅读。在vanilla JS中还有其他答案。