我已经加载到页面上隐藏的iframe内容,我通过多种元素想回路页面上,并使用jquery获取文本。
这里是我当前的代码:
$('#myiFrame').contents().find('div.air').each(function (index) {
alert($(this).text());
});
它似乎只找到了一个DIV与类“空气”的,虽然在页面上两个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
});