国产探花免费观看_亚洲丰满少妇自慰呻吟_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中內容方法,希望對想要了解這方面信息的人有所幫助,程序員要與時俱進,不斷學習更多的知識。

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

圖片精選

主站蜘蛛池模板: 襄垣县| 三台县| 舟曲县| 宜君县| 陇川县| 称多县| 封开县| 合阳县| 青阳县| 保靖县| 皮山县| 荔浦县| 汨罗市| 勐海县| 扎囊县| 三门县| 青冈县| 昭苏县| 南陵县| 柞水县| 慈溪市| 中西区| 海宁市| 广元市| 双峰县| 五莲县| 兰州市| 高平市| 左贡县| 天祝| 洮南市| 上栗县| 莱西市| 临清市| 江孜县| 哈密市| 南宁市| 郯城县| 英德市| 衡阳市| 泰顺县|