parent.html页面:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#if{background-color: #e1e1e1;}
</style>
</head>
<body>
<div id="parentDiv">
this id parent div;
</div>
<iframe id="if" width=420 height=330 name=aa frameborder=0 src="child.html"></iframe>
<script type="text/javascript" src="../jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function(){
//用于在parent页面,隐藏iframe内显示的div;
$(document).bind('click', function(){
$(aa.window.document).find('#dd').hide();
})
})
</script>
</body>
</html>
child.html页面:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#dd{
width: 100px;
height: 100px;
border: 1px solid #000;
display: none;
}
</style>
</head>
<body>
<input type="button" value="btn" id="btn">
<div id="dd">
1111111111<br>
1111111111<br>
1111111111<br>
1111111111<br>
1111111111<br>
</div>
<script type="text/javascript" src="../jquery-1.9.1.js"></script>
<script>
$(function(){
$('#btn').bind('click', function(){
$('#dd').show();
//下面代码用于改变parent页面的内容;
$(parent.window.document).find('#parentDiv').html('parentDiv changed by iframe');
})
//用于在iframe内部隐藏div;
$(document).bind('click', function(e){
if(e.target.tagName.id != 'dd' && e.target.tagName.id != 'btn'){
$('#dd').hide();
}
})
})
</script>
</body>
</html>