分割一个html标签 [英] Splitting an html tags

查看:148
本文介绍了分割一个html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < div id =id1> 
您好!
< br>
< p> ok< p>
< div>
< img class =some class src = >
< / div>
< b> ok1< b>
< div>
< img class =some class src =>
< / div>
< p> end< p>
< / div>

我想分割这个HTML内容,例如输出将是:

$(#id1)。find('img')。each(function(){
var result = somefunction(this)
alert(result)
//第一次循环后 - Hi HElP ME< br>< p> ok< p>
//第二次=< b> ok1< b>
//第三次=< p>结束< p>
})


任何人都可以为我演示这个。由于许多图片没有显示,所以请给我一个通用的解决方案。

解决方案

  $('#id1')。find('img')。each(function(index){


var split_text = $(this).html()。split(/< img [^>]> /)[index];
alert(split_text)
});


<div id="id1">
    "Hi HElP ME
    <br>
    <p>ok<p>
    <div>
         <img class = "some class src="">
    </div>
    <b>ok1<b>
    <div>
         <img class = "some class src="">
    </div>
    <p>end<p>
</div>

I want to split this html content such tha output will be:

$("#id1").find('img').each(function(){
    var result = somefunction(this)
    alert(result)
    //After first loop- "Hi HElP ME<br><p>ok<p>
    // Second time =<b>ok1<b>
    // third time  = <p>end<p>
})

Could anyone give me demo for this.As number of images are not shown so please give me a general solution

解决方案

$('#id1').find('img').each(function(index){


var split_text = $(this).html().split(/<img[^>]*>/)[index];
alert(split_text)
});

这篇关于分割一个html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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