jQuery Mobile 教程
1. jQuery Mobile 教程 2. jQuery Mobile 简介 3. jQuery Mobile 安装 4. jQuery Mobile 页面 5. jQuery Mobile 过渡 6. jQuery Mobile 按钮 7. jQuery Mobile 按钮图标 8. jQuery Mobile 工具栏 9. jQuery Mobile 导航栏 10. jQuery Mobile 可折叠块 11. jQuery Mobile 网格 12. jQuery Mobile 列表视图 13. jQuery Mobile 列表内容 14. jQuery Mobile 表单 15. jQuery Mobile 表单输入 16. jQuery Mobile 表单选择 17. jQuery Mobile 表单滑动条 18. jQuery Mobile 主题 19. jQuery Mobile 事件 20. jQuery Mobile 触摸事件 21. jQuery Mobile 滚屏事件 22. jQuery Mobile 方向改变事件 23. jQuery Mobile 实例 24. jQuery Mobile Data 属性 25. jQuery Mobile 图标 26. jQuery Mobile页面事件 27. jQuery Mobile CSS 类

jQuery Mobile 按钮

jQuery Mobile 按钮


Mobile 应用程序是建立在您想要显示的简单的点击事物上。





在 jQuery Mobile 中创建按钮

在 jQuery Mobile 中,按钮可通过三种方式创建:

  • 使用 <button> 元素
  • 使用 <input> 元素
  • 使用带有 data-role="button" 的 <a> 元素

<button>

<button>按钮</button>

55面试教程网 »

<input>

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

55面试教程网 »

<a>

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

55面试教程网 »

在 jQuery Mobile 中,按钮会自动样式化,让它们在移动设备上更具吸引力和可用性。我们推荐您使用带有 data-role="button" 的 <a> 元素在页面间进行链接,使用 <input> 或 <button> 元素进行表单提交。


导航按钮

如需通过按钮在页面间进行链接,请使用带有 data-role="button" 属性的 <a> 元素:

实例

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

55面试教程网 »


内联按钮

默认情况下,按钮占满整个屏幕宽度。如果你想要一个仅是与内容一样宽的按钮,或者如果您想要并排显示两个或多个按钮,请添加 data-inline="true":

实例

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

55面试教程网 »


组合按钮

jQuery Mobile 提供了一个简单的方法来将按钮组合在一起。

请把 data-role="controlgroup" 属性和 data-type="horizontal|vertical" 一起使用来规定是否水平或垂直组合按钮:

实例

<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>

55面试教程网 »

默认情况下,组合按钮是垂直组合,它们之间没有外边距和空间。并且只有第一个和最后一个按钮是圆角,以便它们组合在一起的时候创建一个漂亮的外观。


后退按钮

如需创建后退按钮,请使用 data-rel="back" 属性(这会忽略锚的 href 值):

实例

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

55面试教程网 »


更多链接按钮实例

描述 实例
ui-btn-b 修改按钮颜色为黑色,字体为白色(默认为灰色背景,黑色字体)。 55面试教程网
ui-corner-all 为按钮添加圆角 55面试教程网
ui-mini 制作小按钮 55面试教程网
ui-shadow 为按钮添加阴影 55面试教程网

如果你需要使用更多的样式,每个样式类使用空格隔开,如: class="ui-btn ui-btn-inline ui-btn-corner-all ui-shadow"

默认情况下 <input> 按钮有圆角及阴影效果。 <a> 和 <button> 元素没有。

更完整的CSS类,请查看我们的 jQuery Mobile CSS 类参考手册

下一章演示如何在按钮上加上图标。