jQuery UI API - Spinner Widget
Category
Usage
**Description:** Enhances text input for entering numeric values with up/down buttons and arrow-key handling.
**Version added:** 1.9
The spinner, or number stepper widget, is the perfect control for handling all kinds of numeric input. It lets users type a value directly or spin an existing value with the keyboard, mouse, or wheel. When combined with Globalize, you can even spin to display currencies and dates for different locales.
The spinner uses two buttons to overlay the text input with increments and decrements of the current value. It adds key events so the same increments and decrements can be done with the keyboard. The spinner represents Globalizenumber formatting and parsing.
Keyboard interaction
- UP: Increments the value by one step.
- DOWN: Decrements the value by one step.
- PAGE UP: Increments the value by one page.
- PAGE DOWN: Decrements the value by one page.
After clicking a spin button with the mouse, focus stays in the text field.
When the spinner is not read-only (), the user can type a value, which may produce an invalid value (below the minimum, above the maximum, a step mismatch, non-numeric input). When stepping, whether programmatically or via the spin buttons, the value is coerced to a valid value (for details, see stepUp() and stepDown() description.
Theming
The Spinner Widget uses jQuery UI CSS Framework to define the styles for its look and feel. To use the styles specific to the spinner, you can use the following CSS class names:
ui-spinner: The outer container of the spinner.ui-spinner-input: The element instantiated by the Spinner Widget.ui-spinner-button: The button control used to increment or decrement the spinner value. The up button additionally has aui-spinner-upclass, and the down button additionally has aui-spinner-downclass。
Depends on
- UI Core
- Widget Factory
- Button Widget
- Globalize(External, optional; when creating a selector on
cultureandnumberFormatoption)
Additional Notes
- This widget requires some functional CSS; otherwise it will not work. If you create a custom theme, use the widget-specific CSS file as a starting point.
- This widget manipulates the element's value programmatically, so changing the element's value does not fire a native
changeevents. - Creating a datepicker on it is not supported, because it would cause a UI conflict with the native picker.
, it would cause a UI conflict with the native spinner.
Example
A plain numeric selector.
旋转器部件(Spinner Widget)演示