Latest web development tutorials

jQuery Mobile Button

Mobile applications are built on the simple click of things you want to display.





Create a button in jQuery Mobile

In jQuery Mobile, the button can be created in three ways:

  • Use <button> element
  • Use <input> element
  • Use <a> elements with data-role = "button" of

<Button>

<button>按钮</button>

try it"

<Input>

<input type="button" value="按钮">

try it"

<a>

<a href="#" data-role="button" >按钮</a>

try it"

lamp In jQuery Mobile, the button will automatically styling, make them more attractive and availability on mobile devices. We recommend that you use <a> elements with data-role = "button" of the link, use the <input> or <button> element between the pages form submission.


Navigation buttons

For through the button link between pages, use <a> elements with data-role = "button" property:

Examples

< a href="#pagetwo" data-role="button" >访问第二个页面</a>

try it"


Inline button

By default, the button occupies the entire width of the screen. If you want a content only as wide as a button, or if you want to display two or more buttons side by side, add the data-inline = "true":

Examples

<a href="#pagetwo" data-role="button" data-inline="true" >访问第二个页面</a>

try it"


A combination of buttons

jQuery Mobile provides a simple way to combine a button.

Please put data-role = "controlgroup" attributes and data-type = "horizontal | vertical" used together to specify whether horizontal or vertical combinations of buttons:

Examples

<div data-role="controlgroup" data-type="horizontal" >
<a href="#anylink" data-role="button">按钮 1</a>
<a href="#anylink" data-role="button">按钮 2</a>
<a href="#anylink" data-role="button">按钮 3</a>
</div>

try it"

lamp By default, the buttons are a combination of vertical composition, no margin and space between them. And only the first and last buttons are rounded, so that when they are combined together to create a beautiful look.


Back button

To create a Back button, use data-rel = "back" property (which ignores anchor href value):

Examples

<a href="#" data-role="button" data-rel="back" >返回</a>

try it"


More links button instance

class description Examples
ui-btn-b Modify button color is black, the font is white (default gray background, black font). try it
ui-corner-all Button to add rounded corners try it
ui-mini Making small buttons try it
ui-shadow Button to add a shadow try it

Note If you need more styles, each style class separated by a space, such as: class = "ui-btn ui-btn-inline ui-btn-corner-all ui-shadow"

By default, the <input> button has rounded corners and shadow effect. <a> and <button> elements do not.

More complete CSS classes, please see our jQuery Mobile CSS Class Reference Manual .

The next section shows how to add an icon on the button.