jquery怎么点击div之外的地方隐藏div
<styletype="text/css">.A{width:100px;height:50px;background:red;}.B{width:500px;heigh...
<style type="text/css">
.A{ width:100px; height:50px; background:red;}
.B{ width:500px; height:500px; background:blue;}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".B").hide();
$(".A").click(function(){
$(".B").toggle();
});
});
</script>
</head>
<body>
<div class="A">按</div>
<div class="B"></div>
</body>
点击A显示隐藏B,然后怎么点击A、B之外的地方隐藏B呢? 展开
.A{ width:100px; height:50px; background:red;}
.B{ width:500px; height:500px; background:blue;}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".B").hide();
$(".A").click(function(){
$(".B").toggle();
});
});
</script>
</head>
<body>
<div class="A">按</div>
<div class="B"></div>
</body>
点击A显示隐藏B,然后怎么点击A、B之外的地方隐藏B呢? 展开
1个回答
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>last.html</title>
<style>
.A {
width: 100px;
height: 50px;
background: red;
}
.B {
width: 500px;
height: 500px;
background: blue;
}
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$ (document).ready (function ()
{
$ (".B").hide ();
$ (".A").click (function ()
{
$ (".B").toggle ();
});
}).click (function (e)
{
e = e || window.event;
if (e.target != $ ('.A')[0] && e.target != $ ('.B')[0])
{
$ ('.B').hide ();
}
});
</script>
</head>
<body>
<div class="A">按fffffffff</div>
<div class="B">ffffffffffff</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询