从jquery中的innerHtml中删除Img标记 [英] Remove Img tag from innerHtml in jquery

查看:129
本文介绍了从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 use Regex for this.

var imgRegex = new RegExp("<img[^>]*?>", "g");


This Regex matches the image 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 that alert is showing the string without the image tag (only the div).


这篇关于从jquery中的innerHtml中删除Img标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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