从字符串中删除HTML(在JSON响应中) [英] remove HTML from a string (in JSON response)

查看:103
本文介绍了从字符串中删除HTML(在JSON响应中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var json = {
    "Item": {
        "Items": {
         "Body": "<SPAN style=\"LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA\">\"We have all been inoculated with Christianity, and are never likely to take it seriously now! You put some of the virus of some dreadful illness into a man's arm, and there is a little itchiness, some scratchiness, a slight discomfort, disagreeable, no doubt, but not the fever of the real disease, the turning and the tossing, and the ebbing strength. And we have all been inoculated with Christianity, more or less. We are on Christ's side, we wish him well, we hope that He will win, and we are even prepared to do something for Him, provided, of course, that He is reasonable, and does not make too much of an upset among our cozy comforts and our customary ways. But there is not the passion of zeal, and the burning enthusiasm, and the eagerness of self-sacrifice, of the real faith that changes character and wins the world.\"<B>A.J. Gossip<\/B><\/SPAN>",
        },

    }
};
var someString = json.Item.Body.replace(/<br\s*\/?\s*>/g,"\n");   
alert(someString);
​

我收到 HTML 我的回复中的标签,我应该删除或解析它。我怎么能这样做呢。我为 BR 标签做了,但现在似乎还有其他标签。

I am getting HTML tags in my response, which i should remove or parse it. How can i go about this. I did for BR tags, but now it seems there are other tags too coming in.

推荐答案

我认为你需要的只是一个简单的正则表达式来从内容中去除html样式标签。试试这个。

I think all you need is a simple regex to strip html style tags from the content. Try this.

str.replace(/<\/?[^>]+>/gi, '')

这篇关于从字符串中删除HTML(在JSON响应中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆