`

js/jquery实现点击div层外,隐藏div

阅读更多

js

document.onmousedown=function(e){
    var target = e.target;
    //alert(target.id);
    var sea = target.getAttribute("sea");
    if(sea!="sea"){
    	if(get("seaList").style.display!="none"){
    		get("seaList").style.display="none";
		}
    }
};

 

jquery

$(document).bind('click',function(e){
	var target = jQuery(e.target);
	//alert(target.attr("id"));
	alert(target.closest(".seaVal").length+","+target.closest(".seaList").length);
	if(target.closest(".seaVal").length!=1&&target.closest(".seaList").length!=1)
	{
		if($(".seaList").show()){
			$(".seaList").hide();
		}
	}
});

 

1
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics