js父页面中使用子页面的方法
iframe是非常常用的一个html元素,如果在父页面中使用子页面的方法应该怎么写呢,下面就做一下简单的介绍。
一、父页面代码
<html>
<head>
<metacharset="gb2312">
<title>父页面</title>
<scripttype="text/javascript">
functionparentFunction()
{
alert('functioninparent');
}
functioncallChild()
{
child.window.childFunction();
/*
child为iframe的name属性值,
不能为id,因为在FireFox下id不能获取iframe对象
*/
}
</script>
</head>
<body>
<iframename="child"src="./child.html"></iframe>
</body>
</html>
二、iframe中的代码
<html>
<head>
<metacharset="gb2312">
<title>iframe代码</title>
<scripttype="text/javascript">
functionchildFunction()
{
alert('functioninchild');
}
functioncallParent()
{
parent.parentFunction();
}
</script>
</head>
<body>
</body>
</html>
上面两个代码可以在父页面和子页面对对方的函数进行相互调用,比较简单,不多介绍了。
希望本文所述对大家学习javascript程序设计有所帮助。
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特