jquery-mobile表單的創(chuàng)建方法詳解
本文實(shí)例講述了jquery-mobile表單的創(chuàng)建方法。分享給大家供大家參考,具體如下:
一、注意事項(xiàng)
1. <form> 元素必須設(shè)置 method 和 action 屬性
2. 每個(gè)表單元素必須設(shè)置唯一的 "id" 屬性。
該 id 在站點(diǎn)的頁面中必須是唯一的。
這是因?yàn)?jQuery Mobile 的單頁面導(dǎo)航模型允許許多不同的“頁面”同時(shí)呈現(xiàn)。
3. 每個(gè)表單元素必須有一個(gè)標(biāo)記(label)。
請(qǐng)?jiān)O(shè)置 label 的 for 屬性來匹配元素的 id。
二、各種屬性的使用
【文本框】
data-role="fieldcontain" 大于480px 自動(dòng)與label 同到一行
<div data-role="fieldcontain"> <label for="lname">姓:</label> <input type="text" name="lname" id="lname"> <label for="fname">名:</label> <input type="text" name="fname" id="fname"> </div>
如果不希望使用 jquery-mobile的樣式
data-role="none"
【搜索框】
加上data-role="fieldcontain" 一行 不加每個(gè)標(biāo)簽一行
<div data-role="fieldcontain"> <label for="search">Search:</label> <input type="search" name="search" id="search"> <div data-role="fieldcontain">
【單選框】
<fieldset data-role="controlgroup">
<legend>請(qǐng)選擇您的性別:</legend>
<label for="male">男性</label>
<input type="radio" name="gender" id="male" value="male">
<label for="female">女性</label>
<input type="radio" name="gender" id="female" value="female">
</fieldset>
【復(fù)選框】
<fieldset data-role="controlgroup">
<legend>請(qǐng)選擇您喜愛的顏色:</legend>
<label for="red">紅色</label>
<input type="checkbox" name="favcolor" id="red" value="red">
<label for="green">綠色</label>
<input type="checkbox" name="favcolor" id="green" value="green">
<label for="blue">藍(lán)色</label>
<input type="checkbox" name="favcolor" id="blue" value="blue">
</fieldset>
[注意]:?jiǎn)螐?fù)選水平分組
可在fieldset 標(biāo)簽中添加屬性
data-type="horizontal"
預(yù)選某個(gè)按鈕 可以使用:
input 的 checked
【選擇菜單】
普通選擇菜單,有點(diǎn)丑
<fieldset data-role="fieldcontain"> <label for="day">選擇日期</label> <select name="day" id="day"> <option value="mon">星期一</option> <option value="tue">星期二</option> <option value="wed">星期三</option> </select> </fieldset>
自定義選擇菜單
使用屬性:
data-native-menu="false"
<fieldset data-role="fieldcontain">
<label for="day">選擇天</label>
<select name="day" id="day" data-native-menu="false">
<option value="mon">星期一</option>
<option value="tue">星期二</option>
<option value="wed">星期三</option>
<option value="thu">星期四</option>
<option value="fri">星期五</option>
<option value="sat">星期六</option>
<option value="sun">星期日</option>
</select>
</fieldset>
【多選菜單】
需要使用自定義的
multiple="multiple" data-native-menu="false"
<fieldset> <label for="day">您可以選擇多天:</label> <select name="day" id="day" multiple="multiple" data-native-menu="false"> <option>天</option> <option value="mon">星期一</option> <option value="tue">星期二</option> <option value="wed">星期三</option> <option value="thu">星期四</option> <option value="fri">星期五</option> <option value="sat">星期六</option> <option value="sun">星期日</option> </select> </fieldset>
【滑動(dòng)條】
<div data-role="fieldcontain"> <label for="points">Points:</label> <input type="range" name="points" id="points" value="50" min="0" max="100"> </div>
max - 規(guī)定允許的最大值
min - 規(guī)定允許的最小值
step - 規(guī)定合法的數(shù)字間隔
value - 規(guī)定默認(rèn)值
<div data-role="fieldcontain"> <label for="points">Points:</label> <input type="range" name="points" id="points" value="50" min="0" max="100" data-highlight="true"> </div>
【翻轉(zhuǎn)切換開關(guān)】
data-role="slider"
默認(rèn)選中可加 selected
<div data-role="fieldcontain"> <label for="switch">Toggle Switch:</label> <select name="switch" id="switch" data-role="slider"> <option value="on">On</option> <option value="off">Off</option> </select> </div>
顏色主題
【主題樣式】
a 默認(rèn)。黑色背景上的白色文本。
b 藍(lán)色背景上的白色文本 / 灰色背景上的黑色文本
c 亮灰色背景上的黑色文本
d 白色背景上的黑色文本
e 橙色背景上的黑色文本
一般情況下 使用上面的顏色 可以直接使用屬性
data-theme="e"
如果要改變對(duì)話框(遮罩)的背景色
data-overlay-theme="e" (放在page上)
改變可折疊的背景顏色
data-theme="b" data-content-theme="e" (放在collapsible)
主題劃分按鈕
data-split-theme="e" (放在 listview)
【添加新樣式】
/*為工具條添加樣式
改變背景色 需要改倆個(gè)地方:background 和 background-image*/
.ui-bar-f{border:1px solid #333;
background:#f00;
color:#fff;font-weight:700;
text-shadow:0 -1px 0 #000;
background-image:-webkit-gradient(linear,left top,left bottom,from(#3c3c3c),to(#111));
background-image:-webkit-linear-gradient(#3c3c3c,#111);
background-image:-moz-linear-gradient(#3c3c3c,#111);
background-image:-ms-linear-gradient(#3c3c3c,#111);
background-image:-o-linear-gradient(#3c3c3c,#111);
background-image:linear-gradient(#3c3c3c,#111)
}
.ui-bar-f,.ui-bar-f input,.ui-bar-f select,.ui-bar-f textarea,.ui-bar-f button{font-family:Helvetica,Arial,sans-serif}
.ui-bar-f .ui-link-inherit{color:#fff}
.ui-bar-f a.ui-link{color:#7cc4e7;font-weight:700}
.ui-bar-f a.ui-link:visited{color:#2489ce}
.ui-bar-f a.ui-link:hover{color:#2489ce}
.ui-bar-f a.ui-link:active{color:#2489ce}
/*為內(nèi)容添加樣式*/
.ui-body-f{font-weight:bold;color:purple;}
.ui-body-f,.ui-overlay-f{border:1px solid #444;
background:#222;color:#fff;
text-shadow:0 1px 0 #111;
font-weight:400;
background-image:-webkit-gradient(linear,left top,left bottom,from(#444),to(#222));
background-image:-webkit-linear-gradient(#444,#222);
background-image:-moz-linear-gradient(#444,#222);
background-image:-ms-linear-gradient(#444,#222);
background-image:-o-linear-gradient(#444,#222);
background-image:linear-gradient(#444,#222)
}
.ui-overlay-f{background-image:none;border-width:0}
.ui-body-f,.ui-body-f input,.ui-body-f select,.ui-body-f textarea,.ui-body-f button{font-family:Helvetica,Arial,sans-serif}
.ui-body-f .ui-link-inherit{color:#fff}
.ui-body-f .ui-link{color:#2489ce;font-weight:700}
.ui-body-f .ui-link:visited{color:#2489ce}
.ui-body-f .ui-link:hover{color:#2489ce}
.ui-body-f .ui-link:active{color:#2489ce}
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery切換特效與技巧總結(jié)》、《jQuery遍歷算法與技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQueryMobile之窗體長(zhǎng)內(nèi)容的缺陷與解決方法實(shí)例分析
- jquery mobile實(shí)現(xiàn)可折疊的導(dǎo)航按鈕
- jQuery Mobile漏洞會(huì)有跨站腳本攻擊風(fēng)險(xiǎn)
- jquery mobile移動(dòng)端幻燈片滑動(dòng)切換效果
- jQuery-mobile事件監(jiān)聽與用法詳解
- jquery-mobile基礎(chǔ)屬性與用法詳解
- jQuery Mobile和HTML5開發(fā)App推廣注冊(cè)頁
- 使用jQuery mobile NuGet讓你的網(wǎng)站在移動(dòng)設(shè)備上同樣精彩
相關(guān)文章
jQuery實(shí)現(xiàn)仿百度帖吧頭部固定導(dǎo)航效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)仿百度帖吧頭部固定導(dǎo)航效果,涉及jquery針對(duì)頁面高度計(jì)算與樣式的動(dòng)態(tài)添加及刪除技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-08-08
在jquery中處理帶有命名空間的XML數(shù)據(jù)
如果你在做AJAX應(yīng)用,則你可能經(jīng)常會(huì)用到j(luò)query(或者其他框架)處理服務(wù)返回的數(shù)據(jù)。如果用Jquery處理Json格式,將是相當(dāng)方便的。2011-06-06
jquery實(shí)現(xiàn)滑屏大圖定時(shí)收縮為小banner圖片的廣告代碼
這篇文章主要介紹了jquery實(shí)現(xiàn)滑屏大圖定時(shí)收縮為小banner圖片的廣告代碼,可實(shí)現(xiàn)大幅廣告圖的漸顯效果及定時(shí)收縮功能,點(diǎn)擊左上角關(guān)閉按鈕還可隱藏廣告圖片,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-09-09
jQuery+css實(shí)現(xiàn)的切換圖片功能代碼
這篇文章主要介紹了jQuery+css實(shí)現(xiàn)的切換圖片功能代碼,涉及jQuery響應(yīng)鼠標(biāo)事件動(dòng)態(tài)變換頁面元素樣式的相關(guān)技巧,需要的朋友可以參考下2016-01-01
關(guān)于jquery input textare 事件綁定及用法學(xué)習(xí)
目前1.7以上,jquery的事件綁定已經(jīng)用on替換了原來的bind,接下來為大家介紹下bind的使用方法及input textare事件,感興趣的朋友可以參考下哈2013-04-04
jquery做的一個(gè)簡(jiǎn)單的屏幕鎖定提示框
這篇文章主要介紹了使用jquery做的一個(gè)簡(jiǎn)單的屏幕鎖定提示框,需要的朋友可以參考下2014-03-03
javascript錯(cuò)誤的認(rèn)識(shí)不用關(guān)心內(nèi)存管理
因?yàn)槔厥盏拇嬖?,讓javascript等高級(jí)語言開發(fā)者產(chǎn)生了一個(gè)錯(cuò)誤的認(rèn)識(shí),以為可以不用關(guān)心內(nèi)存管理,需要的朋友可以了解下2012-12-12

