search

Home  >  Q&A  >  body text

javascript - How to use jQuery to hide the menu by clicking elsewhere on the page?

PHP中文网PHP中文网2751 days ago705

reply all(3)I'll reply

  • 習慣沉默

    習慣沉默2017-06-15 09:23:47

    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()

    reply
    0
  • 迷茫

    迷茫2017-06-15 09:23:47

    $("#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();

    });

    reply
    0
  • 学习ing

    学习ing2017-06-15 09:23:47

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

    reply
    0
  • Cancelreply