比如有一个区块, 当点击了这个区块的外部时,让这个区块消失。 问题是怎么判断是否点击了某区域的外部?
解决方案 »
- 请教js高手jQuery的jQuer.fn.extend内部实现机制是什么样的
- 如何交换DOM元素位置?
- 菜鸟求助!网页中嵌入flash的遇到的问题
- 关于mapabc API使用遇到的一些问题
- 第一次 发帖 问个问题`` 怎么用javascript 在页面加载的时候自动 生成一个 渐进背景颜色
- !!!!!!请问在JAVASCRIPT中是否有办法判断字符的全角和半角.望高手指点!!!!!!
- Div被Object标签里的插件绘的图层给遮了,跪求各位老师指导,拯救一条绳命吧
- 请帮忙看看我这句话错在什么地方了?
- 如何能跳过这个系统confirm确认框呀?
- promise.then().then()是依次执行的吗?下面的代码为什么没有按顺序执行?
- 树形导航菜单
- 关于用javascript实现隔段时间保存一次的问题
$("thisArea").hide();
})
算一下你当前DIV的位置
如果left,top超过DIV的宽和高就隐藏。
<html>
<head>
<title> New Document </title>
<meta charset="gb2312">
<script src="http://code.jquery.com/jquery-1.6.1.js"></script>
<style>
/*如果网页内容大于一屏可以不写*/
html,body{height:100%}
</style>
</head>
<body>
<div style="width:300px;height:400px;position:absolute;top:50%;left:50%;margin-left:-150px;margin-top:-200px;background:#ccc;" id="ceshi"></div>
</body>
<script>
$('body').click(function(e){
if( !$.contains($('#ceshi')[0],e.target) && $('#ceshi')[0] != e.target){
$('#ceshi').hide();
}
});
</script>
</html>
document.body.onclick=function()
{
divShow.style.display = "none";
};
divShow.onclick=function(){
if(e && e.stopPropagation){
//W3C取消冒泡事件
e.stopPropagation();
}else{
//IE取消冒泡事件
window.event.cancelBubble = true;
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div style='width:200px; height:200px; border:1px solid #000' id='div'>
<p style='width:100px; height:100px; border:1px solid red'></p>
</div><script type='text/javascript'>
var div = document.getElementById('div');
document.documentElement.onclick = function(e)
{
var t ;
e = e || window.event , t = e.srcElement || e.target;
if(!div.contains(t)) div.style.display='none';
}
</script></body>
</html>