We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

按钮就是可以点击的东西。事件处理程序可以用来捕获鼠标、键盘和其他事件。它通常呈现为一个灰色开始长方形。您可以指定按钮的label 属性来将按钮的文字设置好,或者直接写在标签中间也行。

更多信息请参阅 XUL tutorial.

accesskey, autocheck, checkState, checked, command, crop, dir, disabled, dlgtype, group, icon, image, label, open, orient, tabindex, type
accessKey, accessibleType, autoCheck, checkState, checked, command, crop, dir, disabled, dlgType, group, image, label, open, orient, tabIndex, type


<button label="Press Me"
        oncommand="alert('You pressed me!');"/>


类型: character【字符】
本属性允许为控件(元素)设定一个字符作为快捷键,这个字符应该是 label 属性文本中的一个字符。该字符将会被加下划线以重点强调,平台和主体的变换并不影响这一表现行为。 当用户点击 ALT (在其他平台上具有类似功能的键) 和这个字符对应的按键时, 控件(元素)将立刻被从窗口中的某处激活或/并且获得焦点 。虽说字符不分大小写,但是当label中存在大写字符和小写字符时,快捷键的字符将首先选择与之完全匹配的那一个,如果label中存在两个或更多的与accesskey字符相同的字符,其中的第一个字符将被加下划线。



  <label value="Enter Name" accesskey="e" control="myName"/>
  <textbox id="myName"/>
  <button label="Cancel" accesskey="n"/>
  <button label="Ok" accesskey="O"/>

See also

label attribute, acceltext attribute

类型: boolean
如果此属性为 true,或空白, 每次点击按钮时,此按钮的状态检查都会被执行一次。如果此属性为false, 检查会手动的被拒绝。当autocheck值为true的时候,按钮将会变为多选框或者单选框。

Type: integer, values 0, 1, or 2
This attribute may be used to create three state buttons, numbered 0, 1 and 2. When in state 0 or 1, pressing the button will switch to the opposite state. When in state 2, pressing the button will switch to state 0. This means that the button acts like a checkbox except that there is a third state which must be set manually by adjusting the check state. If you wish to have different behavior for how the states are adjusted, set the autoCheck attribute to false and adjust the state with a script. The type attribute must be set to checkbox for buttons with a check state. Constants for the possible values for this attribute are in the nsIDOMXULButtonElement interface.
Type: boolean
Indicates whether the element is checked or not.
Use hasAttribute() to determine whether this attribute is set instead of getAttribute().
For buttons, the type attribute must be set to checkbox or radio for this attribute to have any effect.<magic name="\"PAGENAME\"/"></magic>
Type: element id
Set to the id of a command element that is being observed by the element.

Type: one of the values below
If the label of the element is too big to fit in its given space, the text will be cropped on the side specified by the crop attribute. An ellipsis will be used in place of the cropped text. If the box direction is reversed, the cropping is reversed.
  • start: The text will be cropped on its left side.
  • end: The text will be cropped on its right side.
  • left: The text will be cropped on its left side.
  • right: The text will be cropped on its right side.
  • center: The text will be cropped in the middle, showing both the start and end of the text normally.
  • none: The text will be not be cropped using an ellipsis. However, the text will simply be cut off if it is too large. The side depends on the CSS text alignment.

Type: one of the values below
The direction in which the child elements of the element are placed.
For scales, the scale's values are ordered from left to right (for horizontal scales) or from top to bottom (for vertical scales)  For other elements, the elements are placed left to right or top to bottom in the order they appear in the XUL code
For scales, the scale's values are ordered from right to left (for horizontal scales) or from bottom to top (for vertical scales). For other elements, they are placed right to left or bottom to top. This is reverse of the order in which they appear in the XUL code.






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

// Enabling back an element by removing the "disabled" attribute

Firefox 3.5 note

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

Type: one of the values below
The dialog type of the button, used only when the button is in a dialog box. You can use this feature to replace the standard dialog box buttons with custom buttons, yet the dialog event methods will still function. For example, if the dlgType is set to accept, the button will replace the dialog box's accept button, which is usually labeled OK. Using this attribute on a button that is not in a dialog box has no effect. The following values can be used as the dialog type:
The OK button, which will accept the changes when pressed.
The cancel button which will cancel the operation.
A help button for displaying help about the dialog.
A button to show more information. This might be a button or a disclosure triangle.
An optional additional button.
A second optional additional button.
Type: string group name
Buttons with type="radio" and the same value for their group attribute are put into the same group. Only one button from each group can be checked at a time. If the user selects one the buttons, the others in the group are unchecked.
Mozilla 1.8
Type: string
This attribute should be used to set the usage for common buttons. Some platforms display these buttons with a small icon indicating their usage. This should be used in place of the image attribute. Possible values include: accept, cancel, help, open, save, find, clear, yes, no, apply, close, print, add, remove, refresh, go-forward, go-back, properties, select-font, select-color, network. If you are using a button that matches one of these common usages, use the icon attribute to indicate this. See the appearance of the different icons on some available platforms.
Type: image URL
The URL of the image to appear on the element. If this attribute is empty or left out, no image appears. The position of the image is determined by the dir and orient attributes.

Type: string
The label that will appear on the element. If this is left out, no text appears.
label 在元素上显示。如果左侧出界,则不显示任何文字。

Type: boolean
For the menu type buttons, the open attribute is set to true when the menu is open. The open attribute is not present if the menu is closed.



  • horizontally: 子控件会被按照在xul源文件中出现的位置依次布置在一行中。
  • vertically: 子控件会被按照在xul源文件中出现的位置依次布置在一列中。
当用户按下 "tab" 键时焦点移动到元素上的顺序。tabindex 数字越大,顺序越靠后。

Type: one of the values below
The type of button. If this attribute is not present, a normal button is created. Leave the attribute out for a normal button.
This type of button can be in two states. The user can click the button to switch between the states. This is not the same as a checkbox because it looks like a button.
Set the type attribute to the value menu to create a button with a menu popup. Place a menupopup element inside the button in this case. The user may click anywhere on the button to open and close the menu.
You can also use the value menu-button to create a button with a menu. Unlike the menu type, this type requires the user to press the arrow to open the menu, but a different command may be invoked when the main part of the button is pressed.
Similar to the menu type, this opens a popup. Place a panel element inside the button. panel elements are popups that support any type of content.
The button acts like a radio button. Only one button in the group can be on a once.
This button will fire its command event repeatedly while the mouse button is held down.



Type: character
Gets and sets the value of the accesskey attribute.

Type: integer
A value indicating the type of accessibility object for the element.

Type: boolean
Gets and sets the value of the autoCheck attribute.
Type: integer, values 0, 1, or 2
Gets and sets the value of the checkState attribute.
Type: boolean
Gets and sets the value of the checked attribute.
Type: boolean
Gets and sets the value of the disabled attribute.

Type: string
Gets and sets the value of the dlgType attribute.
Type: image URL
Gets and sets the value of the image attribute.

Type: string
Gets and sets the value of the label attribute.

Type: boolean
Gets and sets the value of the open attribute.
Type: integer
Gets and sets the value of the tabindex attribute.


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()

nsIAccessibleProvider, nsIDOMXULButtonElement


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