如何使用Javascript / jQuery从div内容中去除HTML标签? [英] How to strip HTML tags from div content using Javascript/jQuery?

查看:77
本文介绍了如何使用Javascript / jQuery从div内容中去除HTML标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个 div 标签,并将其内容存储在一个变量中。如果该标签包含 p,b 或任何其他标签,则应将其从字符串中删除。如何才能做到这一点?

解决方案

使用正则表达式。



<$ p>< code> var regex = /(<([+] +)>)/ ig
var body =< p> test< / p>
var result = body.replace(regex,);

alert(result);

这里是 DEMO



希望这有助于您。


I had made one div tag and stored its contents in a variable. If this tag contains p,b or any other tags then it should be removed from string. How can I achieve this?

解决方案

use the regular expression.

var regex = /(<([^>]+)>)/ig
var body = "<p>test</p>"
var result = body.replace(regex, "");

alert(result);

HERE IS THE DEMO

Hope this helps.

这篇关于如何使用Javascript / jQuery从div内容中去除HTML标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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