HTML中,如何去掉某个元素下的一些特殊标签?

如题,我们有一个Node元素的innerHTML是这样的:

<div>These vignettes illustrate different consequences of scarcity capturing attention. In the previous chapter, we saw how tunneling distorts the trade-offs we make. Trying to focus on making <text>ends</text> meet right now, we fail to consider the impact in the future of raising the insurance deductible. In the vignettes above, in contrast, we catch people as they are trying to focus on something unrelated to their immediate scarcity. We catch the harried executive not when she is <text>putting</text> together her sales pitch but when she is a parent. We catch the student not when he is dealing with making ends meet but when he is trying to focus on his exam. </div>

其中,有两个<text></text>标签,请问有什么方法可以低成本的去掉他们?
多谢

阅读 3.6k
2 个回答
function removeMark(mark,str){
    if(!mark || !str) return false;
    
    var reg = new RegExp("\\<\/?"+mark+".*?\\>","g");
        
    if(reg.test(str)){
        return str.replace(reg,"");
    }else{
        return str;
    }
}

可以去除 <text></text> 或者 <br /> 这样的标签

alert(1)

str.replace(/<text.*?>.*?<\/text>/,"")
$("text").remove()
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题