今天在弄jquery操作iframe中元素:先由iframe中的子頁面b.html給外面的父頁面a.html頁面傳值,再將a.html頁面計算機的值放到b.html頁面上,這里就用到子頁面和父頁面相互傳值,相互調用更自函數這些功能,這里我用一個簡單的例子來介紹一下這些方法。
a.html
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script> <script type="text/javascript"> function f() { $('#a').contents().find("#bbb").val("ddd"); } function fun() { alert('彈出子頁面調用的函數'); } </script> <div id="maindiv">test</div> <iframe id="a" name="a" src="b.html" width="600" height="400"></iframe><br /> <input type="button" value="給子頁面表單賦值" onclick="f()" />
b.html
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script> <script type="text/javascript"> function f() { alert('開始調用父頁面函數'); $(window.parent.fun()); $(window.parent.$("#maindiv").html("子頁面賦過來的值")); } </script> <form name="cform"><input type="text" name="b" id="bbb" /><input name="btn" type="button" onclick="f()" value="調用父函數並給父頁面元素賦值" /></form>
屬性
new : HTML5 中的新屬性。
屬性 | 值 | 描述 |
---|---|---|
align |
|
不贊成使用。請使用樣式代替。 規定如何根據周圍的元素來對齊此框架。 |
frameborder |
|
規定是否顯示框架周圍的邊框。 |
height |
|
規定 iframe 的高度。 |
longdesc | URL | 規定一個頁面,該頁面包含了有關 iframe 的較長描述。 |
marginheight | pixels | 定義 iframe 的頂部和底部的邊距。 |
marginwidth | pixels | 定義 iframe 的左側和右側的邊距。 |
name | frame_name | 規定 iframe 的名稱。 |
sandbox |
|
啟用一系列對 <iframe> 中內容的額外限制。 |
scrolling |
|
規定是否在 iframe 中顯示滾動條。 |
seamless | seamless | 規定 <iframe> 看上去像是包含文檔的一部分。 |
src | URL | 規定在 iframe 中顯示的文檔的 URL。 |
srcdoc | HTML_code | 規定在 <iframe> 中顯示的頁面的 HTML 內容。 |
width |
|
定義 iframe 的寬度。 |
var _body = window.parent;--------------------獲取這個div2的父級窗口,那么自然是這個body了;
var _iframe1 = _body.document,getElementById('rightMain');-------------------根據id獲取iframe1這個對象;
_iframe1.contentWindow.location.reload(true);-----------------------看到reload就該知道是刷新了這個iframe1了。
https://www.cnblogs.com/eco-just/p/9091018.html