Button Widgetversion added: 1.0
Description: Creates a button widget
Buttons
Buttons are coded with standard HTML input
elements, then enhanced by jQuery Mobile to make them more attractive and useable on a mobile device.
Form buttons
For ease of styling, the framework automatically converts any input
element with a type
of submit
, reset
, or button
into a custom styled button - there is no need to add the data-role="button"
attribute. However, if needed, you can directly call the button plugin on any selector, just like any jQuery plugin:
1
|
|
Input type="button" based button:
1
|
|
Input type="submit" based button:
1
|
|
Input type="reset" based button:
1
|
|
Providing pre-rendered markup
You can improve the load time of your page by providing the markup that the button widget would normally create during its initialization.
By providing this markup yourself, and by indicating that you have done so by setting the attribute data-enhanced="true"
, you instruct the button widget to skip these DOM manipulations during instantiation and to assume that the required DOM structure is already present.
When you provide such pre-rendered markup you must also set all the classes that the framework would normally set, and you must also set all data attributes whose values differ from the default to indicate that the pre-rendered markup reflects the non-default value of the corresponding widget option.
The button widget adds a wrapper div
around the input
.
In the example below, pre-rendered markup for a button is provided. The attribute data-corners="false"
is explicitly specified, since the absence of the ui-corner-all
class on the wrapper element indicates that the "corners" widget option is to be false.
1
2
3
4
|
|
Options
cornersType: Boolean
true
This option is also exposed as a data attribute: data-corners="false"
.
Initialize the button with the corners
option specified:
1
|
|
Get or set the corners
option, after initialization:
1
2
3
4
5
|
|
disabledType: Boolean
false
true
.
This option is also exposed as a data attribute: data-disabled="true"
.
Initialize the button with the disabled
option specified:
1
|
|
Get or set the disabled
option, after initialization:
1
2
3
4
5
|
|
enhancedType: Boolean
false
This option is also exposed as a data attribute: data-enhanced="true"
.
Initialize the button with the enhanced
option specified:
1
|
|
Get or set the enhanced
option, after initialization:
1
2
3
4
5
|
|
iconType: String
null
The .buttonMarkup() documentation contains a reference of all the icons available in the default theme.
This option is also exposed as a data attribute: data-icon="star"
.
Initialize the button with the icon
option specified:
1
|
|
Get or set the icon
option, after initialization:
1
2
3
4
5
|
|
iconposType: String
"left"
This option is also exposed as a data attribute: data-iconpos="right"
.
iconshadowType: Boolean
false
Applies the theme shadow to the button's icon if set to true.
This option is also exposed as a data attribute: data-iconshadow="true"
.
initSelectorType: Selector
See below
The default initSelector
for the button widget is:
1
|
|
Note: This option is deprecated in 1.4.0 and will be removed in 1.5.0.
As of jQuery Mobile 1.4.0, the initSelector
is no longer a widget option. Instead, it is declared directly on the widget prototype. Thus, you may specify a custom value by handling the mobileinit
event and overwriting the initSelector
on the prototype:
1
2
3
|
|
Note: Remember to attach the mobileinit
handler after you have loaded jQuery, but before you load jQuery Mobile, because the event is triggered as part of jQuery Mobile's loading process.
The value of this option is a jQuery selector string. The framework selects elements based on the value of this option and instantiates button widgets on each of the resulting list of elements.
(version deprecated: 1.4.0)inlineType: Boolean
null (false)
true
, this will make the button act like an inline button so the width is determined by the button's text. By default, this is null (false) so the button is full width, regardless of the feedback content. Possible values: true, false.
This option is also exposed as a data attribute: data-inline="true"
.
miniType: Boolean
null (false)
true
, this will display a more compact version of the button that uses less vertical height by applying the ui-mini
class to the outermost element of the button widget.
This option is also exposed as a data attribute: data-mini="true"
.
shadowType: Boolean
true
This option is also exposed as a data attribute: data-shadow="false"
.
themeType: String
null, inherited from parent
Possible values: swatch letter (a-z).
This option is also exposed as a data attribute: data-theme="b"
.
Initialize the button with the theme
option specified:
1
|
|
Get or set the theme
option, after initialization:
1
2
3
4
5
|
|
wrapperClassType: String
null
This option is also exposed as a data attribute: data-wrapper-class="custom-class"
.
Methods
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
1
|
|
disable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the disable method:
1
|
|
enable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the enable method:
1
|
|
option( optionName )Returns: Object
optionName
.-
optionNameType: StringThe name of the option to get.
Invoke the method:
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
optionName
.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
1
|
|
refresh()Returns: jQuery (plugin only)
If you manipulate a form button via JavaScript, you must call the refresh method on it to update the visual styling.
1
|
|
- This method does not accept any arguments.
Invoke the refresh method:
1
|
|
Events
create( event, ui )Type: buttoncreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the button with the create callback specified:
1
2
3
|
|
Bind an event listener to the buttoncreate event:
1
|
|
Example:
A basic example of a button
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
|
|