Heim  >  Artikel  >  Web-Frontend  >  JQuery操作iframe父页面与子页面的元素与方法(实例讲解)_jquery

JQuery操作iframe父页面与子页面的元素与方法(实例讲解)_jquery

WBOY
WBOYOriginal
2016-05-16 17:14:04906Durchsuche

JQUERY IFRAME
下面简单使用Jquery来操作iframe的一些记录,这个使用纯JS与可以实现。

第一、在iframe中查找父页面元素的方法:
$('#id', window.parent.document)

第二、在父页面中获取iframe中的元素方法:
$(this).contents().find("#suggestBox")

第三、在iframe中调用父页面中定义的方法和变量:
parent.method
parent.value

iframe里用jquery获取父页面body

iframe.html

复制代码 代码如下:




   
it is a iframe

   
<script><BR> $(document).ready(<BR> function()<BR> {<br><br> var c = $(window.parent.document.body) //麻烦的方法: var c = $($(window).eq(0)[0].parent.document).find('body'); ,忘了可以用前面的方法了<br><br> alert(c.html());<BR> }<BR> );<br><br></script>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn