在父頁面調(diào)用子頁面的JS方法
今天弄了一天了,終于在網(wǎng)上找到了解決辦法
注意:問題是在父頁面調(diào)用子頁面的方法。。。。。
父頁面: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>
大家可以根據(jù)自己的需求修改相應(yīng)的代碼即可。。。。。。。
相關(guān)文章
細(xì)數(shù)localStorage的用法及使用注意事項
這篇文章主要介紹了細(xì)數(shù)localStorage的用法及使用注意事項,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04JavaScript實現(xiàn)計算多維嵌套數(shù)組深度
在前端開發(fā)中,經(jīng)常會遇到需要處理多維嵌套的數(shù)據(jù)結(jié)構(gòu),并需要計算出它們的深度,本文就來講講如何使用JavaScript實現(xiàn)計算多維嵌套數(shù)組深度吧2023-06-06window.open不被攔截的簡單實現(xiàn)代碼(推薦)
下面小編就為大家?guī)硪黄獁indow.open不被攔截的簡單實現(xiàn)代碼(推薦) 。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08