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

首頁 > 編程 > JavaScript > 正文

在父頁面調用子頁面的JS方法

2019-11-20 21:55:49
字體:
來源:轉載
供稿:網友

今天弄了一天了,終于在網上找到了解決辦法

注意:問題是在父頁面調用子頁面的方法。。。。。

父頁面:parent.html

復制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>parent</title>
<script>
 function parentFunction() {
  alert('function in parent');
 }

 function callChild() {
  child.window.childFunction();
  /*
   child 為iframe的name屬性值,
   不能為id,因為在FireFox下id不能獲取iframe對象
  */
 }
</script>
</head>
<body>
<input type="button" name="call child"  value="call child" onclick="callChild()"/>
<br/><br/>
<iframe name="child" src="./child.html" ></iframe>
</body>
</html>


子頁面:child.html

復制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>child</title>
<script>
 function childFunction() {
  alert('function in child');
 }

 function callParent() {
  parent.parentFunction();
 }
</script>
</head>
<body>
<input type="button" name="call parent" value="call parent" onclick="callParent()"/>
</body>
</html>


大家可以根據自己的需求修改相應的代碼即可。。。。。。。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凌海市| 盐山县| 襄樊市| 廊坊市| 周口市| 益阳市| 张家口市| 巧家县| 务川| 杂多县| 文水县| 海淀区| 永顺县| 府谷县| 威远县| 合水县| 荣成市| 吉木萨尔县| 凤翔县| 大连市| 双桥区| 徐闻县| 星座| 马鞍山市| 神池县| 蒲城县| SHOW| 潮州市| 松阳县| 额济纳旗| 满洲里市| 新疆| 隆德县| 色达县| 沙河市| 金坛市| 梁山县| 衢州市| 岳阳县| 吉安县| 沂源县|