iframe是非常常用的一個(gè)html元素,如果在父頁(yè)面中使用子頁(yè)面的方法應(yīng)該怎么寫(xiě)呢,下面就做一下簡(jiǎn)單的介紹。
一、父頁(yè)面代碼
<html><head><meta charset=" gb2312"><title>父頁(yè)面</title><script type="text/javascript">function parentFunction() { alert('function in parent');}function callChild() { child.window.childFunction(); /*  child 為iframe的name屬性值,  不能為id,因?yàn)樵贔ireFox下id不能獲取iframe對(duì)象 */}</script></head><body> <iframe name="child" src="./child.html" ></iframe></body></html>二、iframe中的代碼
<html><head><meta charset="gb2312"><title>iframe代碼</title><script type="text/javascript">function childFunction() { alert('function in child');}function callParent() { parent.parentFunction();}</script></head><body></body></html>上面兩個(gè)代碼可以在父頁(yè)面和子頁(yè)面對(duì)對(duì)方的函數(shù)進(jìn)行相互調(diào)用,比較簡(jiǎn)單,不多介紹了。
希望本文所述對(duì)大家學(xué)習(xí)javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注