uTools-Manuals/docs/jQuery/event.stopPropagation.html
2019-04-21 11:50:48 +08:00

55 lines
3.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">event.stopPropagation()</h1>
<div class="entry-meta">
所属分类:<span class="category"><a href="/category/events/">事件</a> &gt; <a href="/category/events/event-object/">事件对象</a></span>
<span class="pull-right">英文文档:<a href="https://api.jquery123.com/event.stopPropagation/" target="_blank">event.stopPropagation()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry method" id="event-stopPropagation1"><h2 class="section-title">
<span class="name">event.stopPropagation()</span><span class="returns">返回: <a href="/Types/#"></a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>防止事件冒泡到DOM树上也就是不触发的任何前辈元素上的事件处理函数。</p>
<ul class="signatures"><li class="signature" id="event-stopPropagation">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.0/">1.0</a></span>event.stopPropagation()</h4>
<ul><li><div class="null-signature">这个方法不接受任何参数。</div></li></ul>
</li></ul>
<div class="longdesc" id="entry-longdesc">
<p>我们可以用 <code>
<a href="/event.isPropagationStopped">event.isPropagationStopped()</a>
</code> 来确定这个方法是否(在那个事件对象上)调用过了。</p>
<p>这个方法对 <a href="/trigger">trigger()</a> 来自定义的事件同样有效。</p>
<p>注意,这不会阻止<em>同一个元素上</em>的其它事件处理函数的运行。</p>
</div>
<h3>Additional Notes:(其他注意事项:)</h3>
<div class="longdesc"><ul>
自从<a href="/live"><code>.live()</code></a>方法处理事件一旦传播到文档的顶部live事件是不可能停止传播的。同样地<a href="/delegate"><code>.delegate()</code></a> 事件将始终传播给其中包含的被委托元素;
元素上的事件将在被委托事件被调用的时候执行。因此,这些处理程序,可以调用<code><a href="/event.stopPropagation">event.stopPropagation()</a></code>或者返回<code>false</code>防止委派处理程序冒泡。
</ul></div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4><span class="desc">Kill the bubbling on the click event.</span></h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$(<span class="string">"p"</span>).click(<span class="keyword">function</span>(event){</code></div></div><div class="container"><div class="line"><code> event.stopPropagation();</code></div></div><div class="container"><div class="line"><code> <span class="comment">// do something</span></code></div></div><div class="container"><div class="line"><code>}); </code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article> </div>
</article>