iframe是非常常用的一個html元素,如果在父頁面中使用子頁面的方法應該怎么寫呢,下面就做一下簡單的介紹。
一、父頁面代碼
<html><head><meta charset=" gb2312"><title>父頁面</title><script type="text/javascript">function parentFunction() { alert('function in parent');}function callChild() { child.window.childFunction(); /* child 為iframe的name屬性值, 不能為id,因為在FireFox下id不能獲取iframe對象 */}</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> 上面兩個代碼可以在父頁面和子頁面對對方的函數進行相互調用,比較簡單,不多介紹了。
希望本文所述對大家學習javascript程序設計有所幫助。



















