需要像jQuery中的foreach那样从所有iframe中获取所有div
因此,从iframe中提取div的代码由@Adil生成,如下所示:需要像jQuery中的foreach那样从所有iframe中获取所有div,jquery,jquery-ui,html,iframe,Jquery,Jquery Ui,Html,Iframe,因此,从iframe中提取div的代码由@Adil生成,如下所示: $(window).load(function () { var filteredContents = $('.test').contents().find('.div_iframe').html(); $('.test').contents().find('body').html(filteredContents); }); <iframe class="test" width="100
$(window).load(function () {
var filteredContents = $('.test').contents().find('.div_iframe').html();
$('.test').contents().find('body').html(filteredContents);
});
<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%;">
HTML如下所示:
$(window).load(function () {
var filteredContents = $('.test').contents().find('.div_iframe').html();
$('.test').contents().find('body').html(filteredContents);
});
<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
复制过来
提前谢谢
更新:
我将进一步解释,这样我就不会得到
close vote
我所做的是,我在iframe中有一个表,我只想得到一个没有任何标题或任何东西的表,因此上面的代码正在过滤它,以便准确地给我包含iframe中的表的div,然后显示它。我的问题是,如果我有多个iframe,那么该表从第一个iframe复制而来,具有相同的信息,并且没有类似于foreach
…的循环。如果您有多个元素,可以使用每个元素来迭代它们,请尝试此方法
<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);
});
});
$(窗口)。加载(函数(){
$('.test')。每个(函数(){
var filteredContents1=$(this.contents().find('.div_iframe').html();
$(this.contents().find('body').html(filteredContents1);
});
});
是的,但这是对iframe的动态调用,因此我无法生成ID,我的iframe看起来是这样的:如果我提交了iframe的操作,需要对您的代码提供帮助,需要采取下一个msjId,有可能吗?我的意思是,如果我在iframe上做了一个动作,它会重新加载,然后它会重新加载所有的标题,我希望它像以前一样只重新加载该部分,即使我不重新加载页面,只重新加载iframe,你知道我的意思吗?在执行操作之后,你需要对加载的每个帧执行这些语句var filteredContents1=$(this).contents().find('.div_iframe').html()$(this).contents().find('body').html(filteredContents1);是的,但是我如何在不重新加载页面的情况下做到这一点,我只希望iframe按照我的要求重新加载,而不需要标题:(?看看jQuery的“each”方法。@jimp在我的情况下,我真的不知道如何使用each
,你能帮忙吗?