qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

jQuery Mobile 表单输入元素

jQuery Mobile 文本输入

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

实例

<form method="post" action="demoform.asp">   <div data-role="fieldcontain">     <label for="fullname">全名:</label>     <input type="text" name="fullname" id="fullname">      <label for="bday">生日:</label>     <input type="date" name="bday" id="bday">      <label for="email">电邮:</label>     <input type="email" name="email" id="email" placeholder="您的邮件地址..">   </div> </form> 

亲自试一试

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

<input placeholder="sometext">

文本框

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

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

实例

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

亲自试一试

搜索框

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

实例

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

亲自试一试

单选按钮

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

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

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

实例

<form method="post" action="demoform.asp">   <fieldset data-role="controlgroup">     <legend>Choose your gender:</legend>       <label for="male">Male</label>       <input type="radio" name="gender" id="male" value="male">       <label for="female">Female</label>       <input type="radio" name="gender" id="female" value="female">    </fieldset> </form> 

亲自试一试

复选框

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

实例

<form method="post" action="demoform.asp">   <fieldset data-role="controlgroup">     <legend>Choose as many favorite colors as you'd like:</legend>       <label for="red">Red</label>       <input type="checkbox" name="favcolor" id="red" value="red">       <label for="green">Green</label>       <input type="checkbox" name="favcolor" id="green" value="green">       <label for="blue">Blue</label>       <input type="checkbox" name="favcolor" id="blue" value="blue">    </fieldset> </form> 

亲自试一试

更多实例

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

实例

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

亲自试一试

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

实例

<div data-role="fieldcontain">   <fieldset data-role="controlgroup">     <legend>Choose your gender:</legend>   </fieldset> </div> 

亲自试一试

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

实例

<input type="radio" checked> <input type="checkbox" checked> 

亲自试一试

posted on 2014-05-23 19:07 顺其自然EVO 阅读(403) 评论(0)  编辑  收藏 所属分类: jQuery Mobile 教程


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜