Jquery-隐藏div

Jquery-隐藏div,jquery,Jquery,我有一个div在里面,像 <form> <div> showing some information here </div> <div id="idshow" style="display:none"> information here </div> </form> 在这里显示一些信息 这里的信息 我在某个按钮单击事件的div(idshow)中查看人口信息。每当我单击div(idshow)外部时,我想要的应该是隐藏

我有一个div在里面,像

<form>
<div>
showing some information here
</div>

<div id="idshow" style="display:none">
information here
</div>

</form>

在这里显示一些信息
这里的信息
我在某个按钮单击事件的div(idshow)中查看人口信息。每当我单击div(idshow)外部时,我想要的应该是隐藏。就像我点击菜单,然后菜单显示,当我点击菜单外,它会隐藏。
我需要使用jquery进行所有操作。您可以这样做:

$(document).click(function(event) {
  var target = $( event.target );

  // Check to see if the target is the div.
  if (!target.is( "div#idshow" )) {
    $("div#idshow").hide();
    // Prevent default event -- may not need this, try to see
    return( false );
  }
});
$(document).click(function() {
  $("#idshow").hide();
});
$("#idshow").click(function(e) {
  e.stopPropagation();
});
这里发生的事情是,当您单击时,
单击
事件会一直冒泡到
文档
,如果它到达那里,我们将隐藏
。但是,当您在
中单击时,您可以通过使用…来阻止气泡上升到
文档
,因此不会触发,简短:)