Use jQuery to hide a DIV when the user clicks outside of it

后端 未结 30 3538
庸人自扰
庸人自扰 2020-11-21 04:28

I am using this code:

$(\'body\').click(function() {
   $(\'.form_wrapper\').hide();
});

$(\'.form_wrapper\').click(function(event){
   event.stopPropagatio         


        
30条回答
  •  心在旅途
    2020-11-21 04:59

    if you have trouble with ios, mouseup is not working on apple device.

    does mousedown /mouseup in jquery work for the ipad?

    i use this:

    $(document).bind('touchend', function(e) {
            var container = $("YOURCONTAINER");
    
              if (container.has(e.target).length === 0)
              {
                  container.hide();
              }
          });
    

提交回复
热议问题