<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
#test{
width: 300px;
height: 300px;
background: pink;
}
</style>
<body>
<div id="test">
</div>
</body>
</html>
<script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function stopPropagation(e) {
if(e.stopPropagation){
e.stopPropagation();
}
else{
e.cancelBubble = true;
}
}
$(document).bind('click', function() {
$('#test').css('display', 'none');
});
$('#test').bind('click', function(e) {
stopPropagation(e);
});
</script>
点击div之外的元素隐藏div(二)
最新推荐文章于 2023-05-04 10:58:16 发布