首页 > 其他 > 详细

点击div外面该div消失(二)

时间:2016-08-07 15:28:09      阅读:277      评论:0      收藏:0      [点我收藏+]

技术分享

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="js/jquery-2.2.2.min.js"></script>
		<style type="text/css">
			.main {
				width: 300px;
				height: 300px;
				background: red;
			}
			
			.content {
				width: 100px;
				height: 100px;
				background: blue;
			}
		</style>
		<script type="text/javascript">
//			$(function() {   //方法一
//				$("#showdiv").click(function(e) {
//					if($("#test").is(":hidden")) {
//						$("#test").fadeIn();
//						e ? e.stopPropagation() : event.cancelBubble = true;
//					}
//				});
//				$("#test").click(function(e) {
//					e ? e.stopPropagation() : event.cancelBubble = true;
//				});
//				$(document).click(function() {
//					$("#test").fadeOut();
//				});
//			})
//          $(function(){   //方法二
//          	$("#showdiv").click(function(e){
//          		alert(e.target.className);
//          		if(e.target.className!=="content"){
//          			$("#test").hide();
////          			$("#showdiv").hide();
//          		}
//          	})
//          	$("#test").click(function(){
//          		alert(1111);
//          		return false;  //阻止事件冒泡到父级DIV
//          	})
//          })
            $(function(){    //方法三
            	$("#showdiv").click(function(){
            		$("#test").hide();
            		return false;
            	})
            	$("#test").click(function(){
            		return false;
            	})
            })
		</script>
	</head>

	<body>
		<div id="showdiv" class="main">
			<div id="test" class="content">

			</div>
		</div>
	</body>

</html>

  

点击div外面该div消失(二)

原文:http://www.cnblogs.com/libin-1/p/5746167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!