需要像jQuery中的foreach来获取所有iframe中的所有div [英] need like foreach in jQuery to take all the divs from all the iframes

查看:555
本文介绍了需要像jQuery中的foreach来获取所有iframe中的所有div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以从iframe中提取div的代码是由@Adil制作的,如下所示:

so the code that extracts the div from the iframe is made by @Adil like this:

$(window).load(function () {
        var filteredContents = $('.test').contents().find('.div_iframe').html();
        $('.test').contents().find('body').html(filteredContents);
});

HTML如下所示:

<iframe class="test" width="100%" height="100%" src="/message.html?msjId=268" style="height:100%;width:100%;">
<iframe class="test" width="100%" height="100%" src="/message.html?msjId=260" style="height:100%;width:100%;">

以及现在应该显示的表,它们应该是两个不同的表,但目前是 msjId 的同一个表,但是从第一个 msjId ...

and the tables that should be displayed now, they should be two different tables, but at the moment is the same table for both msjId but duplicated from the first msjId...

提前致谢!

更新:

我会解释更多,所以我不要得到关闭投票我正在做的是我在iframe中有一个表,我只想得到没有任何标题或任何东西,所以上面的代码过滤到准确地给我一个包含iframe表格的div,然后显示它。我的问题是,如果我有一个以上的iframe然后表从第一个iframe复制相同的信息,并没有像 foreach ...

i will explain more so i don't get close vote what i'm doing is that i have a table in the iframes that i want only to get without any headers or anything so the code above is filtering that to give me exactly that div that contains the table from the iframe and then displays it. my problem is if i have more than one iframe then the table is duplicated from the first iframe with the same info and there's no loop like foreach...

推荐答案

当你有多个元素可以使用它们来迭代它们时,试试这个。

When you have more then one elements you can use each to iterate through them, try this.

<iframe id="frame1" width="100%" height="100%" src="/message.html?msjId=268" style="height:100%;width:100%;">
<iframe id="frame2" width="100%" height="100%" src="/message.html?msjId=260" style="height:100%;width:100%;">

 $(window).load(function () {
     $('.test').each(function(){         

       var filteredContents1 = $(this).contents().find('.div_iframe').html();
       $(this).contents().find('body').html(filteredContents1);       

     });

 });

这篇关于需要像jQuery中的foreach来获取所有iframe中的所有div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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