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

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

js實(shí)現(xiàn)iframe跨頁(yè)面調(diào)用函數(shù)的方法

2024-05-06 16:11:59
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
這篇文章主要介紹了js實(shí)現(xiàn)iframe跨頁(yè)面調(diào)用函數(shù)的方法,實(shí)例展示了iframe中父頁(yè)面調(diào)用子頁(yè)面和子頁(yè)面調(diào)用父頁(yè)面的實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
 
 

本文實(shí)例講述了js實(shí)現(xiàn)iframe跨頁(yè)面調(diào)用函數(shù)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

在項(xiàng)目中難免會(huì)遇到這樣一個(gè)問(wèn)題就是頁(yè)面引入了IFrame并且需要父頁(yè)面調(diào)用子頁(yè)面函數(shù)或者子頁(yè)面需要調(diào)用父頁(yè)面函數(shù)。比如說(shuō):現(xiàn)在有兩個(gè)頁(yè)面parent.html和child.html。其中parent.html中含有IFrame并且IFrame指向child.html。現(xiàn)在需要在parent.html/child.html中調(diào)用child.html/parent.html的一個(gè)js方法。   

具體的代碼實(shí)現(xiàn)如下:

parent.html父頁(yè)面:

復(fù)制代碼代碼如下:
<html> 
<head> 
<script type="text/javascript"> 
  function parent_click(){ 
    alert("來(lái)自父頁(yè)面"); 
  } 
</script> 
</head> 
<body> 
  <input type="button" value="調(diào)用本頁(yè)面函數(shù)" onclick="parent_click();" /> 
  <input type="button" value="調(diào)用子頁(yè)面函數(shù)" onclick='window.frames["childPage"].child_click();' /> 
  <iframe id="childPage" name="childPage" src="inner.html" width="100%" frameborder="0"></iframe> 
</body> 
</html>

 

child.html子頁(yè)面:

復(fù)制代碼代碼如下:
<html> 
<head> 
<script type="text/javascript"> 
  function child_click(){ 
    alert("調(diào)用的子頁(yè)面函數(shù)"); 
  } 
</script> 
</head> 
<body> 
  <input type="button" value="調(diào)用父頁(yè)面函數(shù)" onclick='parent.window.parent_click();' /> 
  <input type="button" value="調(diào)用本頁(yè)面函數(shù)" onclick="child_click();" /> 
</body> 
</html>

 

希望本文所述對(duì)大家基于javascript的web程序設(shè)計(jì)有所幫助。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 洞口县| 永州市| 辉南县| 湘潭市| 四子王旗| 宁德市| 平安县| 江门市| 宁武县| 葫芦岛市| 固安县| 应城市| 荔波县| 双流县| 麻城市| 临颍县| 汝州市| 双城市| 前郭尔| 彰化县| 通州区| 象州县| 卢龙县| 金溪县| 宣威市| 灵寿县| 临沧市| 贵南县| 刚察县| 林周县| 靖边县| 阿拉善右旗| 务川| 砀山县| 松溪县| 台南县| 泰来县| 黄山市| 宁强县| 靖远县| 大厂|