Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery Mobile Buttons

jQuery Mobile Buttons


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



Creating buttons in jQuery Mobile

In jQuery Mobile, buttons can be created in three ways:

Try it »

Try it »

data-role="button"

button

Try it »

lamp In jQuery Mobile, buttons are automatically styled to make them more attractive and usable on mobile devices.We recommend using a with data-role="button" element to link between pages, and a or

Navigation buttons

To link between pages with a button, use a with a data-role="button" attribute element:

Example

<

a href="#pagetwo" data-role="button"

Visit the second page

Try it »


Inline buttons

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

Example

data-inline="true"

Visit the second page

Try it »


Grouped buttons

jQuery Mobile provides an easy way to group buttons together.

Use the data-role="controlgroup" attribute together with data-type="horizontal|vertical" to specify whether to group buttons horizontally or vertically:

Example

data-role="controlgroup" data-type="horizontal"

Button 1

Button 2

Button 3

Try it »

lamp By default, grouped buttons are grouped vertically with no margins or space between them. Only the first and last buttons have rounded corners to create a nice appearance when grouped together.

Back button

To create a back button, use the data-rel="back" attribute (which ignores the anchor's href value):

Example

data-rel="back"

Return

Try it »


More link button examples

class Description Example
ui-btn-b Change the button color to black and the font to white (the default is a gray background with black font). Try it
ui-corner-all Add rounded corners to buttons Try it
ui-mini Make small buttons Try it
ui-shadow Add shadows to buttons Try it

| Note | If you need to use more styles, separate each style class with a space, e.g.: class="ui-btn ui-btn-inline ui-btn-corner-all ui-shadow"

 默认情况下  按钮有圆角及阴影效果。  和 

| --- | --- |

For a more complete list of CSS classes, see our jQuery Mobile CSS Classes Reference Manual。

The next chapter demonstrates how to add icons to buttons.