×

JavaScript 脚本

jQuery 操作iframe

管理员 管理员 发表于2010-11-02 浏览2637 评论0

父操作子ifame
function parentOperateSon() {
          alert( $('#div1', frames['iframe1'].document).html() );    //方法1
          $('#iframe1').contents().find('#div1').html("父操作子");    //方法2
          alert( $(window.frames["iframe1"].document).find("#div1").html() ); //方法3
       }
子iframe操作父
      function SonOperateParent() {
          $(parent.document).contents().find('#hello').html('ifram1父元素');   //方法1
          $(top.document).contents().find('#hello').html('ifram1父元素');    //方法2
          $(window.parent.document).contents().find('#hello').html('ifram1父元素');   //方法3
       }
子iframe操作子iframe、兄弟框架
      function SonOprateOtherSon() {
          $('#iframe2', top.document.body).contents().find('#div1').html('ifram1操作iframe2');   //方法1
          $('#iframe2', parent.document.body).contents().find('#div1').html('ifram1操作iframe2');    //方法2
          $('#iframe2', window.parent.document.body).contents().find('#div1').html('ifram1操作 iframe2');   //方法3
       }父操作子ifame
function parentOperateSon() {
          alert( $('#div1', frames['iframe1'].document).html() );    //方法1
          $('#iframe1').contents().find('#div1').html("父操作子");    //方法2
          alert( $(window.frames["iframe1"].document).find("#div1").html() ); //方法3
       }
子iframe操作父
      function SonOperateParent() {
          $(parent.document).contents().find('#hello').html('ifram1父元素');   //方法1
          $(top.document).contents().find('#hello').html('ifram1父元素');    //方法2
          $(window.parent.document).contents().find('#hello').html('ifram1父元素');   //方法3
       }
子iframe操作子iframe、兄弟框架
      function SonOprateOtherSon() {
          $('#iframe2', top.document.body).contents().find('#div1').html('ifram1操作iframe2');   //方法1
          $('#iframe2', parent.document.body).contents().find('#div1').html('ifram1操作iframe2');    //方法2
          $('#iframe2', window.parent.document.body).contents().find('#div1').html('ifram1操作 iframe2');   //方法3
       }