JQuery操作iframe父页面与子页面的元素与方法

JQuery操作iframe父页面与子页面的元素与方法
下面简单使用Jquery来操作iframe的一些记录,这个使用纯JS也可以实现。
第一、在iframe中查找父页面元素的方法:
  $('#id', window.parent.document)
第二、在父页面中获取iframe中的元素方法:
  $(this).contents().find("#suggestBox")
  $("#openEdit_ifr",parent.document).contents().find('#mission_pin').empty().html(inner_html);
  $("#cas_login_frame",parent.document).contents().find('#left_div').empty().html(123);
第三、在iframe中调用父页面中定义的方法和变量:
  parent.method
  parent.value
第四、父页面调用iframe内的JS的方法,无须给iframe加id,只需用Jq选中iframe就行了
  $("#id").find("iframe")[0].contentWindow.function()
--------------少年不努力,长大搞程序。欢迎关注,如有错误,恳请指正。
原文地址:https://www.cnblogs.com/oycyqr/p/8806898.html