javascript - 循环遍历 Iframe 中的多个元素

标签 javascript jquery iframe find

我将内容加载到页面上的隐藏 iframe 中,我想遍历页面上的多个元素并使用 jquery 获取文本。

这是我当前的代码:

$('#myiFrame').contents().find('div.air').each(function (index) {
       alert($(this).text());
     });

虽然页面上有两个div,但它似乎只找到了一个类为'air'的div。我的代码怎么错了?

编辑:我应该说它们是页面上的两个“div.air”,不在同一父项下。

HTML 类似于:

<section id="blah">
<div class="air"> text here </div>
</section>
<section id="blah2">
<div class="air"> text here </div>
</section>

最佳答案

得出我自己的答案:

$('#iframe').contents().find('.air').each(function(){

    var foo = $(this).html();
    //do your Stuff here

});

关于javascript - 循环遍历 Iframe 中的多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10943156/

相关文章:

javascript - 将变量设置为 Google 可视化数据聚合的结果

javascript - 使用javascript从json对象获取 parent 姓名

JavaScript-ForEach

javascript - iOS 上的 Jquery 移动 - 动量滚动可防止调用单击处理程序

javascript - JQuery通过单击同一行上的按钮获取第一个td

java - spring 文件上传中回调

javascript - 区分 console.log 和两个 iframe

javascript - 设置包含保留字的代码CSS

javascript - 通过 json 和 ajax 将事件从 Controller 获取到完整日历

html - Youtube 嵌入的 iFrame 未出现