代码描述:js父页面 iframe函数。js父页面使用iframe中的函数
iframe是非常常用的一个html元素,如果在父页面中使用子页面的方法应该怎么写呢,下面就做一下简单的介绍。 一.父页面代码:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.51qianduan.com/" /> <title>父页面-51前端</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中的代码:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.51qianduan.com/" /> <title>iframe代码-51前端</title> <script type="text/javascript"> function childFunction() { alert('function in child'); } function callParent() { parent.parentFunction(); } </script> </head> <body> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能