jQuery Mobile Forms
jQuery Mobile automatically adds styles to HTML forms, making them more attractive and friendlier to touch.
jQuery Mobile Form Structure
jQuery Mobile uses CSS to add styles to HTML form elements, making them more attractive and easier to use.
In jQuery Mobile, you can use the following form controls:
- Text inputs
- Search inputs
- Radio Button
- Checkbox
- Select menus
- Sliders
- Flip toggle switches
When using jQuery Mobile forms, you should know:
- Each form element must have a unique "id" attribute. The id must be unique across all pages of the entire site. This is because jQuery Mobile's single-page navigation mechanism causes multiple different pages to be presented at the same time
- Each form element must have a label. Set the label's for attribute to match the element's id
Example
method="post" action="demoform.html"
id="fname"
Try it »
To hide a label, use the class ui-hidden-accessible. This is often used when you use an element's placeholder attribute as a label:
Example
Try it »
Tip: We can use the data-clear-btn="true" attribute to add a button that clears the input field (an X icon on the right side of the input field):
Example
data-clear-btn="true"
Try it »
![]() |
The button to clear the input field can be used in elements, but not in |
|---|
jQuery Mobile form icons
The button code in the form is standard HTML Elements (button, reset, submit). They automatically render styles and can automatically adapt to both mobile devices and desktop devices:
Example
Try it »
If you need to To add extra styles to buttons, you can use the data-* attributes in the table below:
| property | Value | Description |
|---|---|---|
| data-corners | true | false | Specify whether the button has rounded corners |
| data-icon | Icon reference manual | Specify the button icon |
| data-iconpos | left | right | top | bottom | notext | Specify icon position |
| data-inline | true | false | Specify whether the button is inline |
| data-mini | true | false | Specify whether it is a mini button |
| data-shadow | true | false | Specify whether to add a shadow effect to the button |
Add an icon to the button:
Try it »
Field container
To make labels and form elements look more suited to wide screens, use the one with the "ui-field-contain" class
