在父頁面調(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ù)自己的需求修改相應的代碼即可。。。。。。。
相關文章
layui+ssm實現(xiàn)數(shù)據(jù)批量刪除功能
本篇文章給大家介紹layui+ssm實現(xiàn)數(shù)據(jù)批量刪除功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-12-12
JS實現(xiàn)很實用的對聯(lián)廣告代碼(可自適應高度)
這篇文章主要介紹了JS實現(xiàn)很實用的對聯(lián)廣告代碼,可實現(xiàn)固定相對位置懸浮展示及跟隨屏幕上下滑動等功能,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09
基于JS實現(xiàn)彈出一個隱藏的div窗口body頁面變成灰色并且不可被編輯
這篇文章主要介紹了基于JS實現(xiàn)彈出一個隱藏的div窗口body頁面變成灰色并且不可被編輯的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-12-12
window.open()實現(xiàn)post傳遞參數(shù)
本文主要向大家介紹了如何使用window.open()實現(xiàn)post傳遞參數(shù)的方法,思路是參考的一位網(wǎng)友的,然后根據(jù)自己的項目需求做了些調(diào)整,這里同樣分享給大家,希望對大家能夠有所幫助。2015-03-03

