Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

command

« XUL Reference home [ 示例 | 属性 | 特性 | 方法 | 相关 ]
command 元素响应不同来源的、对于同一操作的操作请求。比如,剪贴板的粘贴操作,可以来自 “编辑”菜单,可以来自鼠标右键的上下文菜单,也可以来自键盘快捷键。你可以通过 command 的 oncommand 属性调用代码。对于用户来说,从什么地方触发了这个操作并不重要。另外,关闭 command 将自动关闭菜单中的项目和对键盘快捷键的响应。

Commands are identified by their id. If you include the script chrome://global/content/globalOverlay.js in your window, you can use the function goDoCommand function to invoke the command. Using this function has the advantage that the command will be sent to the part of the UI which will respond to it. Typically, this will be the currently focused element.

Like a broadcaster, commands forward attributes to other elements.

More information is available in the XUL tutorial. See also: command attribute, commandset element

Attributes
disabled, label, oncommand

Examples

The following code will send a paste command (cmd_paste) to the currently focused element:

 // First include chrome://global/content/globalOverlay.js
 goDoCommand("cmd_paste");

Example with two buttons

<command id="cmd_openhelp" oncommand="alert('Help');"/>
<button label="Help" command="cmd_openhelp"/>
<button label="More Help" command="cmd_openhelp"/>

Attributes

disabled
Type: boolean
Indicates whether the element is disabled or not. If this element is set to true the element is disabled. Disabled elements are usually drawn with grayed-out text. If the element is disabled, it does not respond to user actions, it cannot be focused, and the command event will not fire.


Image:XUL_ref_attr_disabled.png
<!-- Checkbox enables/disables the button -->
<checkbox label="Enable button" 
    onclick="document.getElementById('buttRemove').disabled = this.checked"/>
<button id="buttRemove" label="Remove All" disabled="true"/>
label
Type: string
The label that will appear on the element. If this is left out, no text appears.
label 在元素上显示。如果左侧出界,则不显示任何文字。

oncommand
Type: script code
This event handler is called when the command is activated. This occurs when a user selects a menu item or presses a keyboard shortcut attached to the command.

Properties

Inherited Properties
align, attributes, allowEvents, baseURI, boxObject, builder, childElementCount, childNodes, children, className, clientHeight, clientLeft, clientTop, clientWidth, collapsed, contextMenu, controllers, database, datasources, dir, firstChild, firstElementChild, flex, height, hidden, id, lastChild, lastElementChild, left, localName, maxHeight, maxWidth, menu, minHeight, minWidth, namespaceURI, nextElementSibling, nextSibling, nodeName, nodeType, nodeValue, observes, ordinal, orient, ownerDocument, pack, parentNode, persist, prefix, previousElementSibling, previousSibling, ref, resource, scrollHeight, scrollLeft, scrollTop, scrollWidth, statusText, style, tagName,textContent, tooltip, tooltipText, top, width

Methods

Inherited from XUL element
blur, click, doCommand, focus, getElementsByAttribute

Inherited from DOM element
addEventListener(), appendChild(), dispatchEvent(), getAttribute(), getAttributeNode(), getAttributeNodeNS(), getAttributeNS(), getElementsByTagName(), getElementsByTagNameNS(), hasAttribute(), hasAttributeNS(), hasAttributes(), hasChildNodes(), insertBefore(), isSupported(), normalize(), removeAttribute(), removeAttributeNode(), removeAttributeNS(), removeChild(), removeEventListener(), replaceChild(), setAttribute(), setAttributeNode(), setAttributeNodeNS(), setAttributeNS()

文档标签和贡献者

 此页面的贡献者: ziyunfei, Mhoudg, Cuimingda
 最后编辑者: ziyunfei,