javascript - How to use jQuery to hide the menu by clicking elsewhere on the page?
PHP中文网
PHP中文网 2017-06-15 09:21:47
0
3
701

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
習慣沉默

You should look like this

$(document).bind("click",function(e){ 
    //通过e.target判断
} 

e.target != "You click on the element that needs to be displayed" then execute hide()

迷茫

$("#a").on("click", function(e){

if($(".class").is(":hidden")){
    $(".class").show();
}else{
    $(".class").hide();
}

$(document).one("click", function(){
    $(".class").hide();
});

e.stopPropagation();

});
$(".class").on("click", function(e){

e.stopPropagation();

});

学习ing

There is no problem with this answer, it is quite correct

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template