iframe父页面调用子页面方法

子页面.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>   
<script type="text/javascript">
$(function(){
$('.selectAll').click(function(){
    $('input[name="check-item"]').prop('checked',this.checked);
})

 window.parent.parentHello();
})
 function sonHello() {
            alert("this is son hello function!");
        }

</script>
</head>
<body>
<div>
<input type="checkbox" class="selectAll" name="selectAll">全选 
<input type="checkbox" name="check-item" οnclick="all();" />周一
<input type="checkbox" name="check-item"  οnclick="all();" />周一
<input type="checkbox" name="check-item"  οnclick="all();" />周一
<input type="checkbox" name="check-item"  οnclick="all();" />周一
<input type="checkbox" name="check-item"  οnclick="all();" />周一
</div>


</body>
</html>

父页面.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>   
<script type="text/javascript">

$(function(){
  $('#father').click(function(){
    myframe.window.sonHello();
  })

})
 function parentHello() {
            alert("this is parent hello function!");
        }
      //  window.frames[0].sonHello();


</script>
</head>
<body>
<div>
<button id="father">点击</button>
<iframe src="checkall.html" name="myframe"></iframe>
</div>


</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42835381/article/details/109330239