aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/tech/xul/attribute/allowevents/index.html
blob: 5d17570f740aea1ed05b0ea1b36684008c3dbbe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
title: allowevents
slug: Mozilla/Tech/XUL/Attribute/allowevents
tags:
  - XUL Attributes
  - XUL Reference
translation_of: Archive/Mozilla/XUL/Attribute/allowevents
---
<div class="noinclude"><span class="breadcrumbs xulRefAttr_breadcrumbs">« <a href="/zh-CN/docs/XUL_Reference">XUL Reference home</a></span></div>

<dl>
 <dt><code id="a-allowevents"><a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Attribute/allowevents">allowevents</a></code></dt>
 <dd>Type:
 <i>boolean<br>
 </i>
 类型:boolean</dd>
 <dd>If true, events are passed to children of the element. Otherwise, events are passed to the element only.<br>
 如果为真,事件向子元素传递。否则,事件只传递到当前元素。</dd>
</dl>

<div class="noinclude">
<p>On <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/listitem" title="listitem">listitem</a></code> and <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/titlebar" title="titlebar">titlebar</a></code> elements, mouse events normally do not get sent to their children; instead they are retargeted to the <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/listitem" title="listitem">listitem</a></code> and <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/titlebar" title="titlebar">titlebar</a></code> element itself. This means that elements placed inside a listitem do not respond to events, and instead clicking the mouse simply selects that item within the list. By setting the allowevents attribute to <code>true</code>, this special behavior is disabled, and the events are targeted the same as other elements.<br>
 在 <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/listitem" title="listitem">listitem</a></code><code><a href="/zh-CN/docs/Mozilla/Tech/XUL/titlebar" title="titlebar">titlebar</a></code> 元素中,鼠标事件通常不发送给子元素;相反它们重定向到 <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/listitem" title="listitem">listitem</a></code><code><a href="/zh-CN/docs/Mozilla/Tech/XUL/titlebar" title="titlebar">titlebar</a></code> 元素本身。这意味着,放置在listitem内部的元素并不响应事件,而点击鼠标仅仅是选择在列表中的元素。当设置allowevents属性为真时,这种特殊的响应被禁止,事件则被定向到其他相同的元素。</p>

<p>For <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/menu" title="menu">menu</a></code>, <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/menuseparator" title="menuseparator">menuseparator</a></code>, <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/menuitem" title="menuitem">menuitem</a></code> and <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/treecol" title="treecol">treecol</a></code> elements, as well as menu buttons, and the popup <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/datepicker" title="datepicker">datepicker</a></code>, mouse events are also retargeted to the element itself. However, the allowevents attribute is handled in a different way. Instead, the allowevents may be set to <code>true</code> on a descendant instead. This does the same thing in that it allows events to be targeted normally, but allows this to be different for each descendant.</p>

<p>This behavior is used for menus, for instance, to allow a menu button to behave as a menu when clicking on it, yet have part of the menu behave as a button. For the latter, the allowevents attribute is set to <code>true</code> to have a click on the child button receive events instead of targeting all events at the menu.</p>
</div>

<p></p>