# command

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.

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

<button label="Help" command="cmd_openhelp"/>
<button label="More Help" command="cmd_openhelp"/>

### Attributes

disabled

#### 示例：

// Disabling an element
document.getElementById('buttonRemove').setAttribute("disabled", "true");

// Enabling back an element by removing the "disabled" attribute
document.getElementById('buttonRemove').removeAttribute("disabled");

Firefox 3.5 note

For keyset elements, support for this attribute was added in Firefox 3.5.

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, , allowEvents, , boxObject, builder, , , , className, , , , , collapsed, contextMenu, controllers, database, datasources, dir, , , flex, height, hidden, id, , , left, , maxHeight, maxWidth, menu, minHeight, minWidth, , , , , , , observes, ordinal, orient, , pack, , persist, , , , ref, resource, , , , , statusText, style, ,, tooltip, tooltipText, top, width