JQuery实现点击div以外的位置隐藏该div窗口

<p>鼠标点击div外的地方让div窗口隐藏消失,实现方法有很多,在本文将为大家介绍下jquery中时如何实现的,感兴趣的朋友不要错过了哈</p><p>jquery实现鼠标点击div外的地方div窗口隐藏消失的</p><p>代码如下:</p><pre class="brush:js;toolbar:false">&lt;!DOCTYPEhtmlPUBLIC&quot;-//W3C//DTDXHTML1.0Transitional//EN&quot;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;htmlxmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head&gt; &lt;metahttp-equiv=&quot;Content-Type&quot;content=&quot;text/html;charset=utf-8&quot;/&gt; &lt;title&gt;网页特效展示中心&lt;/title&gt; &lt;styletype=&quot;text/css&quot;&gt; .pop{width:200px;height:130px;background:#080;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;scripttype=&quot;text/javascript&quot;src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;&gt;&lt;/script&gt; &lt;scripttype=&quot;text/javascript&quot;&gt; $(function(){ $(document).bind(&quot;click&quot;,function(e){ vartarget=$(e.target); if(target.closest(&quot;.pop&quot;).length==0){ $(&quot;.pop&quot;).hide(); } }) }) &lt;/script&gt; &lt;divclass=&quot;pop&quot;&gt;&lt;/div&gt; 点击空白的地方指定div隐藏消失了 &lt;/body&gt; &lt;/html&gt;</pre><p>代码如下:</p><p>class=&quot;bigPic&quot;的div是被显示或隐藏的div,另外.case &gt; ul &gt; li是class=&quot;bigPic&quot;的父级元素</p><pre class="brush:js;toolbar:false">$(&quot;body&quot;).bind(&quot;click&quot;,function(evt){ if($(evt.target).parents(&quot;.case&gt;ul&gt;li&quot;).length==0) { $(&#39;.bigPic&#39;).hide(); } });</pre>
RangeTime:0.006008s
RangeMem:196.99 KB
返回顶部 留言