场景:<div class="down-con"> <div class="down"> .......</div> </div> 点击down-con这个div来切换 down 这个div的显示或隐藏。
用冒泡的方法:
1.为外层div添加点击事件,在事件中先取消事件冒泡
$('.down-con').click(function(event){
event.stopImmediatePropagation();//取消事件冒泡;
var display =$(".down-con .down").css('display');
if(display == 'none'){
$(".down-con .down").css("display","block");
}else if(display == 'block'){
$(".down-con .down").css("display","none");
}
});
2.事件冒泡
$(document).bind("click",function(){
$(".down-con .down").css("display","none");
})