<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://www.pc120xz.cn/scripts/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="top" style="height:99px; border:1px solid #933; background-color:#999999;">
</div>
<div id="divmain">
<iframe name="contentFrame" id="contentFrame" width="100%" height="500" allowtransparency="true" scrolling="no" border="0" frameborder="0" src="main.html" ></iframe>
</div>
<div id="bottom" style="height:99px; border:#06F solid 1px; background-color:#999999;">此处显示 id "bottom" 的内容</div>
<script type="text/javascript">
$("#contentFrame").load(function(){
var mainheight = $(this).contents().find("body").height();
$(this).height(mainheight);
});
$(document).ready(function(){
$("#ListShow").bind("click",function(){
$('#Main_pl1').animate({height:'show', opacity: 'show'}, 'normal',function(){
$('#Main_pl1').show();
});
$('#ListShow').attr('style','display:none');
$('#ListHide').attr('style','display:block');
return false;
});
$("#ListHide").bind("click",function(){
$('#Main_pl1').animate({height:'hide', opacity: 'hide'}, 'normal',function(){
$('#Main_pl1').hide();
});
$('#ListShow').attr('style','display:block');
$('#ListHide').attr('style','display:none');
});
$(document).bind("click",function(event){
if($(event.target).isChildOf("#Main_pl1") == false){
$('#Main_pl1').animate({height:'hide', opacity: 'hide'}, 'normal',function(){
$('#Main_pl1').hide();
});
$('#ListShow').attr('style','display:block');
$('#ListHide').attr('style','display:none');
}
});
$.fn.isChildAndSelfOf = function(b){
return (this.closest(b).length > 0);
};
$.fn.isChildOf = function(b){
return (this.parents(b).length > 0);
};
});
</script>
<div id="MainA1" style="position:fixed;left:0px;bottom:2px;_position:absolute;">
<div id="Main_pl1" style="display:none;">
<div class="Main_pl1m" style="width:400px; height:200px; background:#666666;">点击此DIV外任意地方隐藏此DIV 或点击iframe子页面中隐藏 父页面DIV</div>
</div>
<div id="Main_pm1" style="width:400px; height:120px;">
<div class="Main_pm1m overz" style="border:#9CC solid 1px;">
<span title="打开列表" id="ListShow" style="display:block;">测试这个</span>
<span title="关闭列表" id="ListHide" style="display:none;">测试这个</span>
</div>
</div>
</div>在同一页面可以 但DIV浮动在iframe上时 失效
</body>
</html>
之前不是回过你了?iframe和父页是不同的区域,点击iframe是无法响应父页的click事件的,用透明的层遮盖住iframe(跨域)或者没有跨域的情况下给iframe添加click事件隐藏div
$("#contentFrame").load(function () {
var mainheight = $(this).contents().find("body").height();
$(this).height(mainheight);
//////////////////////////////增加下面的代码触发父页绑定的click事件
$(this).contents().click(function () {
$(parent.document).trigger('click');
});
//////////////////////////////
});
或者透明层遮盖住iframe
<div id="divmain" style="position:relative">
<div style="position:absolute;left:0px;top:0px;width:100%;height:100%;background:#000;filter:alpha(opacity=0);opacity:0"></div>
<iframe name="contentFrame" id="contentFrame" width="100%" height="500" allowtransparency="true" scrolling="no" border="0" frameborder="0" src="http://www.baidu.com" ></iframe>
</div>
添加document.onclick,判断点击对象,如果不是div,那就处理成隐藏
<!DOCTYPE html>
<html>
<body>
<button id='test'>点击这里</button>
<p id="demo"></p>
<script>
document.onclick=function(e){
alert(e.target.id);
}
</script>
</body>
</html>
实现鼠标点击div外的地方div窗口隐藏消失的
. 代码如下:
点击空白的地方指定div 隐藏消失了
. 代码如下:
class="bigPic"的div是被显示或隐藏的div,另外.case > ul > li是class="bigPic"的父级元素
$("body").bind("click",function(evt){
if($(evt.target).parents(".case > ul > li").length==0)
{
$('.bigPic').hide();
}
});
我看到y.qq.com可以的