按钮就是可以点击的东西。事件处理程序可以用来捕获鼠标、键盘和其他事件。它通常呈现为一个灰色开始长方形。您可以指定按钮的label
属性来将按钮的文字设置好,或者直接写在标签中间也行。
更多信息请参阅 XUL tutorial.
- Attributes
- accesskey, autocheck, checkState, checked, command, crop, dir, disabled, dlgtype, group, icon, image, label, open, orient, tabindex, type
- Properties
- accessKey, accessibleType, autoCheck, checkState, checked, command, crop, dir, disabled, dlgType, group, image, label, open, orient, tabIndex, type
Examples
<button label="Press Me" oncommand="alert('You pressed me!');"/>
Attributes
-
accesskey
- Type: character
-
This should be set to a letter that is used as a shortcut key. This letter should be one of the characters that appears in the
text for the element.label
Example
<vbox> <label value="Enter Name" accesskey="e" control="myName"/> <textbox id="myName"/> <button label="Cancel" accesskey="n"/> <button label="Ok" accesskey="O"/> </vbox>
See also
label
attribute, acceltext
attribute
-
autocheck
- Type: boolean
-
If this attribute is
true
, or left out, themenuitem
check mark will update each time the menu item is selected. If this attribute isfalse
, the check mark must be adjusted manually.
checkState
- Type: integer, values
0
,1
, or2
- 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 tofalse
and adjust the state with a script. Thetype
attribute must be set tocheckbox
for buttons with a check state. Constants for the possible values for this attribute are in thensIDOMXULButtonElement
interface.
-
checked
- Type: boolean
- Indicates whether the element is checked or not.
-
Use
hasAttribute()
to determine whether this attribute is set instead ofgetAttribute()
. -
For buttons, the
type
attribute must be set tocheckbox
orradio
for this attribute to have any effect.<magic name="\"PAGENAME\"/"></magic>
-
crop
- 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.
-
dir
- Type: one of the values below
- The direction in which the child elements of the element are placed.
-
normal
- 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
-
reverse
- 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.
-
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 thecommand
event will not fire.
<!-- Checkbox enables/disables the button --> <checkbox label="Enable button" onclick="document.getElementById('buttRemove').disabled = this.checked"/> <button id="buttRemove" label="Remove All" disabled="true"/>
dlgtype
- 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 toaccept
, the button will replace the dialog box's accept button, which is usually labeledOK
. 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: accept
- The OK button, which will accept the changes when pressed.
cancel
- The cancel button which will cancel the operation.
help
- A help button for displaying help about the dialog.
disclosure
- A button to show more information. This might be a button or a disclosure triangle.
extra1
- An optional additional button.
extra2
- A second optional additional button.
-
group
- 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.
icon
- 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 theicon
attribute to indicate this. See the appearance of the different icons on some available platforms.
-
image
- 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
andorient
attributes.
-
label
- Type: string
-
The label that will appear on the element. If this is left out, no text appears.
label 在元素上显示。如果左侧出界,则不显示任何文字。
-
open
- Type: boolean
-
For the
menu
type
buttons, theopen
attribute is set totrue
when the menu is open. Theopen
attribute is not present if the menu is closed.
布局(orient)
-
值类型:可以是下面值中的一种。
指定了子控件的布局(orient)为水平分布的(horizontally)或者是垂直分布的(vertically)。默认值依赖于控件本身。你也可以使用-moz-box-orient中的样式属性。- horizontally: 子控件会被按照在xul源文件中出现的位置依次布置在一行中。
- vertically: 子控件会被按照在xul源文件中出现的位置依次布置在一列中。
-
tabindex
- Type: integer
-
The tab order of the element. The tab order is the order in which the focus is moved when the user presses the "tab" key. Elements with a higher
tabindex
are later in the tab sequence.
Properties
-
accessibleType
- Type: integer
- A value indicating the type of accessibility object for the element.
-
checkState
-
Type: integer, values
0
,1
, or2
-
Gets and sets the value of the
checkState
attribute.
Methods
Related
- Interfaces
- nsIAccessibleProvider, nsIDOMXULButtonElement