从jquery中的innerHtml中删除Img标记 [英] Remove Img tag from innerHtml in jquery
本文介绍了从jquery中的innerHtml中删除Img标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在快速观看时的内容,在innerHtml中
< img style =width:100%; height:320px; SRC = IMG / banner03.jpg >
< div class =bjqs-caption>
自动生成的标题3
< / div>
但我在innerHTML中想要的是:
< div class =bjqs-caption>
自动生成的标题3
< / div>
如何从innerHTML删除img标签
解决方案
解决方案
您可以使用Regex
。
var imgRegex = new RegExp ( < img [^>] *?>, g);
这个正则表达式
匹配图像
标签。
匹配后,它只是一个用空格替换匹配的字符串的问题。
str.replace(str.match(imgRegex), );
演示
[演示]正则表达式匹配图像标签 [ ^ ]
你可以看到alert
显示字符串
而没有image
标记(仅限于格
)。
This is What I have when I do quick watch, In the innerHtml
<img style="width: 100%; height: 320px;" src="img/banner03.jpg">
<div class="bjqs-caption">
Automatically generated caption3
</div>
But What I want in the innerHTML as :
<div class="bjqs-caption">
Automatically generated caption3
</div>
How will as remove img tag from the innerHTML
解决方案
Solution
You can useRegex
for this.
var imgRegex = new RegExp("<img[^>]*?>", "g");
ThisRegex
matches theimage
tags.
After matching, it is just a matter of replacing matched string with blank.
str.replace(str.match(imgRegex), "");
Demo
[Demo] Regex to Match Image tags[^]
You can see thatalert
is showing thestring
without theimage
tag (only thediv
).
这篇关于从jquery中的innerHtml中删除Img标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文