Javascript 访问a<;表>;使用jquery创建iframe

Javascript 访问a<;表>;使用jquery创建iframe,javascript,jquery,jquery-ui,iframe,Javascript,Jquery,Jquery Ui,Iframe,我看过一些关于访问iframe内部数据的文章,因此在加载iframe的页面中有这样一个表:… 因此,我只想在iframe中显示这个表,没有任何标题或其他div或任何内容 如何使用jQuery实现这一点 更新: html代码如下所示:我在 HTML如下所示: <iframe class="test" width="100%" height="100%" src="/message.html?msjId=268" style="height:100%;width:100%;"> <

我看过一些关于访问iframe内部数据的文章,因此在加载iframe的页面中有这样一个表:

因此,我只想在iframe中显示这个表,没有任何标题或其他div或任何内容

如何使用jQuery实现这一点

更新:

html代码如下所示:我在

HTML如下所示:

<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
复制过来。

您必须使用jquery load方法而不是ready。As load确保已加载iFrame html。另一方面,ready确保当前页面中的html元素已就绪

$(window).load(function () {  
      var filteredContents = $('#iframeId').contents().find('.table').html();
      $('#iframeId').contents().find('body').html(filteredContents);
});
根据OP请求进行更新。

当您有两个元素时,可以使用ID而不是类,请阅读有关

<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 () {
     var filteredContents1 = $('#frame1').contents().find('.div_iframe').html();
     $('#frame1').contents().find('body').html(filteredContents1);

     var filteredContents2 = $('#frame2').contents().find('.div_iframe').html();
     $('#frame2').contents().find('body').html(filteredContents2);

 });

$(窗口)。加载(函数(){
var filteredContents1=$('#frame1').contents().find('.div_iframe').html();
$('#frame1').contents().find('body').html(filteredContents1);
var filteredContents2=$('#frame2').contents().find('.div_iframe').html();
$('#frame2').contents().find('body').html(filteredContents2);
});
尝试以下操作:

$('iframe-id').contents().find('body').html($('.table').html());

但是iframe页面必须与您的包含页面来自同一域,否则您将收到一个权限被拒绝的错误。

这将显示没有html标记的文本,这是您想要的吗?不,对不起,我的错误,我想显示标记,其中的所有内容就像iframe中的html表一样,只有表没有其他内容您必须使用它,$('.table').html();我试过:
$(document.ready(function(){$('#test').contents().find('#table').html();})但不工作请添加新问题,因为我们已经在很大程度上更改了原始问题。实际上不工作,它在iframe的开头显示了提到的表,然后加载所有页面。我正在使用这个
$(document).ready(function(){
,这可能是因为iframe尚未完成加载。请尝试在$('#iframe id').load中执行上述操作(function(){/*HERE*/});
<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 () {
     var filteredContents1 = $('#frame1').contents().find('.div_iframe').html();
     $('#frame1').contents().find('body').html(filteredContents1);

     var filteredContents2 = $('#frame2').contents().find('.div_iframe').html();
     $('#frame2').contents().find('body').html(filteredContents2);

 });
$('iframe-id').contents().find('body').html($('.table').html());