国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

父頁面讀取和操作iframe中內容方法

2024-05-06 15:45:28
字體:
來源:轉載
供稿:網友

訪問父頁面中iframe的每個元素和訪問一般的頁面元素沒有本質區別,只需要獲取需要在父頁中提前處理的iframe對象,下面是錯新技術頻道小編為大家帶來的父頁面讀取和操作iframe中內容方法,一起來看看吧!

基本的操作方法:
document.frames("frame_id").document.action;
其中,frame_id是該父頁面需要進行操作的iframe的id,action是iframe中的相關操作。
從該方法中,可以看出 document.frames("frame_id")是用來從父頁面中獲取iframe的id的,而后面的document.action同一般的腳本對頁面元素操作一樣,具體舉個例子來說明一下,其中父頁面引用iframe部分如下:

?

<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如下:

?

?

?


<%@ 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>


父頁面中對iframe元素操作的script腳本如下:

?

?

?


<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>


此例描述了在父頁面中讀取iframe中元素以及在父頁面中修改iframe中元素的屬性。

通過此例,我們可以看出,在父頁面中訪問iframe中的各個元素與一般的訪問頁面元素無本質區別,無非是需要在父頁面中事先獲取需要處理的iframe對象,在獲取iframe對象后,其操作基本沒什么特別之處。

綜上就是錯新技術頻道小編為大家分析的父頁面讀取和操作iframe中內容方法,希望對想要了解這方面信息的人有所幫助,程序員要與時俱進,不斷學習更多的知識。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 兴文县| 楚雄市| 巴南区| 清水河县| 本溪市| 屏山县| 舒兰市| 汪清县| 会昌县| 乌兰察布市| 杨浦区| 从江县| 汉川市| 泽普县| 崇信县| 新安县| 株洲县| 广昌县| 嘉鱼县| 彭州市| 广灵县| 兴文县| 巨鹿县| 二手房| 任丘市| 沭阳县| 南皮县| 安远县| 安塞县| 边坝县| 德保县| 宁化县| 衡水市| 平顶山市| 化州市| 昆明市| 武隆县| 兰西县| 阳谷县| 溧阳市| 正宁县|