在父頁面調(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,因?yàn)樵贔ireFox下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)文章
JavaScript實(shí)現(xiàn)商品放大鏡效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)商品放大鏡效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10細(xì)數(shù)localStorage的用法及使用注意事項(xiàng)
這篇文章主要介紹了細(xì)數(shù)localStorage的用法及使用注意事項(xiàng),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04JavaScript實(shí)現(xiàn)計(jì)算多維嵌套數(shù)組深度
在前端開發(fā)中,經(jīng)常會遇到需要處理多維嵌套的數(shù)據(jù)結(jié)構(gòu),并需要計(jì)算出它們的深度,本文就來講講如何使用JavaScript實(shí)現(xiàn)計(jì)算多維嵌套數(shù)組深度吧2023-06-06window.open不被攔截的簡單實(shí)現(xiàn)代碼(推薦)
下面小編就為大家?guī)硪黄獁indow.open不被攔截的簡單實(shí)現(xiàn)代碼(推薦) 。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08javascript 隨機(jī)展示頭像實(shí)現(xiàn)代碼
隨機(jī)展示小頭像,隨機(jī)數(shù)包括 位置、層級、大小、透明度 等2011-12-12