gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:19:05 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com