我正在做这个项目,但遇到了问题。问题是我需要解码从 API 获取的作为 JSON 对象一部分的 html。 html 非常棘手,所以我需要寻求你们的帮助。
这是我需要转换为纯文本的示例值:
<div class=text-primary>\rSave up to 49% bla bla some text, text, text World of text and text text. For text details of text prices, click on the location required.<br>\r <table width=100%><tr><td width=10%></td><td width=80%><div class="well text-center"><h5><b>To text your text text call</b><h5><h5><b>0871 222 text and quote</b></h5><h4><b>ELG2017</b></h4></div></td><td width=10%></td></tr></table>\r
是的,我知道,这太可怕了。好吧,这就是我必须解码的内容..
非常感谢!
最佳答案
text.replace(/<[^>]*>/g, '');
关于javascript - 复杂的 html 到纯文本 - Angular 4/Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44902158/