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>

代码描述:js父页面 iframe函数。js父页面使用iframe中的函数



127 170



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册



×
×
51前端

注册

×
绑定手机

请绑定手机号,在继续操作

×
单次下载支付

应付金额:279

支付完成后,回到下载页面,在进行下载

官方QQ群
意见反馈
qq群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到