87,915
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script type="text/javascript">
document.onclick=function(){
var div = document.getElementById("div");
var loc = getLoc(div);
var e = window.event;
if ((e.clientX >= loc.locX && e.clientX <= (parseInt(loc.locX) + parseInt(div.offsetWidth))) && (e.clientY >= loc.locY && e.clientY <= (parseInt(loc.locY) + parseInt(div.offsetHeight)))){
div.style.display = "";
} else {
div.style.display = "none";
}
}
var loc = function() {
this.locX = 0;
this.locY = 0;
}
function getLoc(el){
var x = el.offsetLeft;
var y = el.offsetTop;
while(el = el.offsetParent){
x += el.offsetLeft;
y += el.offsetTop;
}
var divLoc = new loc();
divLoc.locX = x;
divLoc.locY = y;
return divLoc;
}
</script>
</head>
<body>
<div id="div" style="background-color:yellow;border:1px solid red;width:300px;height:200px;position:absolute;left:300px;top:200px;">
</div>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>floatDiv2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
#show {
border: 1px solid black;
background-color: #E5F0FB;
position: absolute;
width: 150px;
height: 100px;
display: none;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function () {
$(document).click(function (e) {
if (e.target.id != "show") {
$("#show").hide();
}
});
$("a").click(function (e) {
$("#show").css({left: e.clientX, top: e.clientY}).show();
return false;//防止冒泡
});
});
</script>
</head>
<body>
<a href="#">click me</a>
<div id="show"></div>
</body>
</html>
$(document).ready(function(){
$(document).bind('click', Hide);
});
function Hide(e){
if($(e.target)[0].id =="Pop" )
return;
$("#Pop").hide();
}
<html>
<head>
<script type="text/javascript">
document.onclick=function(){
document.getElementById("div").style.display="none";
}
function clickDiv(div){
div.style.display="";
var b = window.event;
b.cancelBubble = true;
}
</script>
</head>
<body>
<div onclick="clickDiv(this)" id="div" style="background-color:yellow;border:1px solid red;width:300px;height:200px;position:absolute;left:300px;top:200px;">
</div>
</body>
</html>
$("#id").hide();// id是要隐藏对象的id