4

我有一个脚本可以剪切 iframe 的一部分(没有标题的 iframe)并显示它。我的问题是,如果我在这个 iframe 中进行操作,iframe 会重新加载,但没有应用 jquery 过滤来只给我那部分,但是 instad 给了我所有带有标题的页面,所以我假设脚本在重新加载时不起作用iframe 没有具有 iframe 的主页的窗口重新加载:

<iframe class="test" 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);       

     });

 });

请问有什么解决办法吗?

4

1 回答 1

1

我认为您还需要为帧添加加载事件。在 document.ready 函数中添加加载事件,如下所示。如果它有效,您可以省略您已经拥有的用于过滤帧数据的窗口加载事件。

  $(document).ready(function(){     
      $('.test').load(function () {

         var filteredContents1 = $('#frame1').contents().find('#divChild').html();
         $('#frame1').contents().find('body').html(filteredContents1);

      });
  });

应提问者要求更新

  $(document).ready(function(){     
      $('.test').load(function () {            

         $('#frame1, #frame2, #frame3').each(function(){
             var filteredContents1 = $(this).contents().find('#divChild').html();
             $(this).contents().find('body').html(filteredContents1);
         });            

      });
  });

.

于 2012-09-24T12:26:48.063 回答