javascript - 复杂的 html 到纯文本 - Angular 4/Javascript

标签 javascript html json angular decode

我正在做这个项目,但遇到了问题。问题是我需要解码从 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/

相关文章:

javascript - 如何根据其中一个元素对整个元素进行排序?

html - 使用 Internet Explorer 在表格单元格中定位绝对值

json - 为什么我在 Angular 2 项目中需要 `typings.json` 文件?

javascript - 在 html 表中动态渲染非结构化 JSON 数据

javascript - 如何对由字母数字字符串组成的数组进行排序?

javascript - 下面的 JavaScript 代码是如何工作的?你能给我一些细节吗?

javascript - '' .charAt(0) 是可靠的 '' 吗?

javascript - jQuery .replaceWith() 方法点击刷新

javascript - 当输入到达值时,Jquery 不应用效果

python - 由于 json 字符串化字典键导致数据丢失