课程表

jQuery Mobile 教程

jQuery Mobile 列表

jQuery Mobile 表单

jQuery Mobile 主题

jQuery Mobile 事件

jQuery Mobile 实例

jQuery Mobile 参考手册

工具箱
速查手册

jQuery Mobile 表单输入

当前位置:免费教程 » 移动开发 » jQuery Mobile

jQuery Mobile 文本输入

输入字段是通过标准的 HTML 元素编写的,jQuery Mobile 会为它们设置专门针对移动设备的美观易用的样式。您还可以使用新的 HTML5 <input> 类型:

实例

  1. <form method="post" action="demoform.asp">
  2. <div data-role="fieldcontain">
  3. <label for="fullname">全名:</label>
  4. <input type="text" name="fullname" id="fullname">
  5.  
  6. <label for="bday">生日:</label>
  7. <input type="date" name="bday" id="bday">
  8.  
  9. <label for="email">电邮:</label>
  10. <input type="email" name="email" id="email" placeholder="您的邮件地址..">
  11. </div>
  12. </form>

亲自试一试

提示:请使用 placeholder 来规定简短的提示,以描述输入字段的预期值:

  1. <input placeholder="sometext">

文本框

请使用 <textarea> 来实现多行文本输入。

注释:文本框会自动扩大,以适应您输入的文本行。

实例

  1. <form method="post" action="demoform.asp">
  2. <div data-role="fieldcontain">
  3. <label for="info">Additional Information:</label>
  4. <textarea name="addinfo" id="info"></textarea>
  5. </div>
  6. </form>

亲自试一试

搜索框

输入类型 type="search" 是 HTML5 中的新类型,用于定义供输入搜索词的文本字段:

实例

  1. <form method="post" action="demoform.asp">
  2. <div data-role="fieldcontain">
  3. <label for="search">Search:</label>
  4. <input type="search" name="search" id="search">
  5. </div>
  6. </form>

亲自试一试

单选按钮

当用户只选择有限数量选项中的一个时,会用到单选按钮。

如需创建一套单选按钮,请添加 type="radio" 的 input 元素以及相应的 label。在 <fieldset> 元素中包装单选按钮。您也可以增加一个 <legend> 元素来定义 <fieldset> 的标题。

提示:请用 data-role="controlgroup" 属性来组合这些按钮:

实例

  1. <form method="post" action="demoform.asp">
  2. <fieldset data-role="controlgroup">
  3. <legend>Choose your gender:</legend>
  4. <label for="male">Male</label>
  5. <input type="radio" name="gender" id="male" value="male">
  6. <label for="female">Female</label>
  7. <input type="radio" name="gender" id="female" value="female">
  8. </fieldset>
  9. </form>

亲自试一试

复选框

当用户选择有限数量选项中的一个或多个选项时,会用到复选框:

实例

  1. <form method="post" action="demoform.asp">
  2. <fieldset data-role="controlgroup">
  3. <legend>Choose as many favorite colors as you'd like:</legend>
  4. <label for="red">Red</label>
  5. <input type="checkbox" name="favcolor" id="red" value="red">
  6. <label for="green">Green</label>
  7. <input type="checkbox" name="favcolor" id="green" value="green">
  8. <label for="blue">Blue</label>
  9. <input type="checkbox" name="favcolor" id="blue" value="blue">
  10. </fieldset>
  11. </form>

亲自试一试

更多实例

如需对单选框或复选框进行水平分组,请使用 data-type="horizontal" 属性:

实例

  1. <fieldset data-role="controlgroup" data-type="horizontal">

亲自试一试

您也可以使用域容器来包装 <fieldset>:

实例

  1. <div data-role="fieldcontain">
  2. <fieldset data-role="controlgroup">
  3. <legend>Choose your gender:</legend>
  4. </fieldset>
  5. </div>

亲自试一试

如果您希望“预选”其中一个按钮,请使用 HTML <input> 标签的 checked 属性:

实例

  1. <input type="radio" checked>
  2. <input type="checkbox" checked>

亲自试一试

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号