我将内容加载到页面上的隐藏 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/