|
document.frames("frame_id").document.action;
其中,frame_id是該父頁(yè)面需要進(jìn)行操作的iframe的id,action是iframe中的相關(guān)操作。
從該方法中,可以看出 document.frames("frame_id")是用來(lái)從父頁(yè)面中獲取iframe的id的,而后面的document.action同一般的腳本對(duì)頁(yè)面元素操作一樣,具體舉個(gè)例子來(lái)說(shuō)明一下,其中父頁(yè)面引用iframe部分如下:
復(fù)制代碼 代碼如下:
<div id="region1" name="region1">
<iframe onload="iframe_test()" frameborder="0" scrolling="no" width="100%" height="500" name="test_iframe" id="test_iframe" src="/testIframe.jsp" src="testIframe.jsp"></iframe>
</div>
testIframe.jsp如下:
復(fù)制代碼 代碼如下:
<%@ page language= "Java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<title>test_iframe</title>
</head>
<body>
<table class="data_form" align="center">
<tr>
<th>testname</th>
<td><input name="testname" type="text" id="testname" value="testname" ></td>
</tr>
<tr>
<th>description</th>
<td><input name="decription" type="text" id="decription" value="testname" /></td>
</tr>
</table>
<br>
<div >
<input name="fs" type="submit" id="fs" value="test" onClick="alert('test');" class="button">
</div>
</body>
</html>
父頁(yè)面中對(duì)iframe元素操作的script腳本如下:
復(fù)制代碼 代碼如下:
<script type="text/Javascript"><!--
function iframe_test(){
if (document.frames("test_iframe").document.getElementById("testname").value=="testname")
{
alert("test successful!");
}
if(document.frames("test_iframe").document.getElementById("decription").value=="")
{
document.frames("test_iframe").document.getElementById("decription").value="description"
}
}
// --></script>
此例描述了在父頁(yè)面中讀取iframe中元素以及在父頁(yè)面中修改iframe中元素的屬性。
通過(guò)此例,我們可以看出,在父頁(yè)面中訪問(wèn)iframe中的各個(gè)元素與一般的訪問(wèn)頁(yè)面元素?zé)o本質(zhì)區(qū)別,無(wú)非是需要在父頁(yè)面中事先獲取需要處理的iframe對(duì)象,在獲取iframe對(duì)象后,其操作基本沒(méi)什么特別之處。
JavaScript技術(shù):從父頁(yè)面讀取和操作iframe中內(nèi)容方法,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。