jquery-mobile 学习笔记之二(表单创建)

落日映苍穹つ 2022-07-31 15:20 214阅读 0赞

绪上

一、注意事项

  1. 元素必须设置 method 和 action 属性
  1. 每个表单元素必须设置唯一的 “id” 属性。
    该 id 在站点的页面中必须是唯一的。
    这是因为 jQuery Mobile 的单页面导航模型允许许多不同的“页面”同时呈现。
  1. 每个表单元素必须有一个标记(label)。
    请设置 label 的 for 属性来匹配元素的 id。

二、各种属性的使用

【文本框】

data-role=”fieldcontain” 大于480px 自动与label 同到一行

  1. <div data-role="fieldcontain">
  2. <label for="lname">姓:</label>
  3. <input type="text" name="lname" id="lname">
  4. <label for="fname">名:</label>
  5. <input type="text" name="fname" id="fname">
  6. </div>

如果不希望使用 jquery-mobile的样式
data-role=”none”

【搜索框】

加上data-role=”fieldcontain” 一行 不加每个标签一行

  1. <div data-role="fieldcontain">
  2. <label for="search">Search:</label>
  3. <input type="search" name="search" id="search">
  4. <div data-role="fieldcontain">

【单选框】

  1. <fieldset data-role="controlgroup">
  2. <legend>请选择您的性别:</legend>
  3. <label for="male">男性</label>
  4. <input type="radio" name="gender" id="male" value="male">
  5. <label for="female">女性</label>
  6. <input type="radio" name="gender" id="female" value="female">
  7. </fieldset>

【复选框】

  1. <fieldset data-role="controlgroup">
  2. <legend>请选择您喜爱的颜色:</legend>
  3. <label for="red">红色</label>
  4. <input type="checkbox" name="favcolor" id="red" value="red">
  5. <label for="green">绿色</label>
  6. <input type="checkbox" name="favcolor" id="green" value="green">
  7. <label for="blue">蓝色</label>
  8. <input type="checkbox" name="favcolor" id="blue" value="blue">
  9. </fieldset>

[注意]:单复选水平分组
可在fieldset 标签中添加属性
data-type=”horizontal”

预选某个按钮 可以使用:
input 的 checked

【选择菜单】

普通选择菜单,有点丑

  1. <fieldset data-role="fieldcontain">
  2. <label for="day">选择日期</label>
  3. <select name="day" id="day">
  4. <option value="mon">星期一</option>
  5. <option value="tue">星期二</option>
  6. <option value="wed">星期三</option>
  7. </select>
  8. </fieldset>

自定义选择菜单
使用属性:data-native-menu=”false”

  1. <fieldset data-role="fieldcontain">
  2. <label for="day">选择天</label>
  3. <select name="day" id="day" data-native-menu="false">
  4. <option value="mon">星期一</option>
  5. <option value="tue">星期二</option>
  6. <option value="wed">星期三</option>
  7. <option value="thu">星期四</option>
  8. <option value="fri">星期五</option>
  9. <option value="sat">星期六</option>
  10. <option value="sun">星期日</option>
  11. </select>
  12. </fieldset>

【多选菜单】

需要使用自定义的
multiple=”multiple”
data-native-menu=”false”

  1. <fieldset>
  2. <label for="day">您可以选择多天:</label>
  3. <select name="day" id="day" multiple="multiple" data-native-menu="false">
  4. <option></option>
  5. <option value="mon">星期一</option>
  6. <option value="tue">星期二</option>
  7. <option value="wed">星期三</option>
  8. <option value="thu">星期四</option>
  9. <option value="fri">星期五</option>
  10. <option value="sat">星期六</option>
  11. <option value="sun">星期日</option>
  12. </select>
  13. </fieldset>

【滑动条】

  1. <div data-role="fieldcontain">
  2. <label for="points">Points:</label>
  3. <input type="range" name="points" id="points" value="50" min="0" max="100">
  4. </div>

max - 规定允许的最大值
min - 规定允许的最小值
step - 规定合法的数字间隔
value - 规定默认值

  1. <div data-role="fieldcontain">
  2. <label for="points">Points:</label>
  3. <input type="range" name="points" id="points" value="50" min="0" max="100" data-highlight="true">
  4. </div>

【翻转切换开关】

data-role=”slider”

默认选中可加 selected

  1. <div data-role="fieldcontain">
  2. <label for="switch">Toggle Switch:</label>
  3. <select name="switch" id="switch" data-role="slider">
  4. <option value="on">On</option>
  5. <option value="off">Off</option>
  6. </select>
  7. </div>

-——颜色主题———

【主题样式】

a默认。黑色背景上的白色文本。
b蓝色背景上的白色文本 / 灰色背景上的黑色文本
c亮灰色背景上的黑色文本
d白色背景上的黑色文本
e橙色背景上的黑色文本

一般情况下 使用上面的颜色 可以直接使用属性
data-theme=”e”

如果要改变对话框(遮罩)的背景色
data-overlay-theme=”e” (放在page上)

改变可折叠的背景颜色
data-theme=”b” data-content-theme=”e” (放在collapsible)

主题划分按钮
data-split-theme=”e” (放在 listview)

【添加新样式】

  1. /*为工具条添加样式*/
  2. 改变背景色 需要改俩个地方:background background-image
  3. .ui-bar-f{border:1px solid #333;
  4. background:#f00;
  5. color:#fff;font-weight:700;
  6. text-shadow:0 -1px 0 #000;
  7. background-image:-webkit-gradient(linear,left top,left bottom,from(#3c3c3c),to(#111));
  8. background-image:-webkit-linear-gradient(#3c3c3c,#111);
  9. background-image:-moz-linear-gradient(#3c3c3c,#111);
  10. background-image:-ms-linear-gradient(#3c3c3c,#111);
  11. background-image:-o-linear-gradient(#3c3c3c,#111);
  12. background-image:linear-gradient(#3c3c3c,#111)
  13. }
  14. .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}
  15. .ui-bar-f .ui-link-inherit{color:#fff}
  16. .ui-bar-f a.ui-link{color:#7cc4e7;font-weight:700}
  17. .ui-bar-f a.ui-link:visited{color:#2489ce}
  18. .ui-bar-f a.ui-link:hover{color:#2489ce}
  19. .ui-bar-f a.ui-link:active{color:#2489ce}
  20. /*为内容添加样式*/
  21. .ui-body-f{font-weight:bold;color:purple;}
  22. .ui-body-f,.ui-overlay-f{border:1px solid #444;
  23. background:#222;color:#fff;
  24. text-shadow:0 1px 0 #111;
  25. font-weight:400;
  26. background-image:-webkit-gradient(linear,left top,left bottom,from(#444),to(#222));
  27. background-image:-webkit-linear-gradient(#444,#222);
  28. background-image:-moz-linear-gradient(#444,#222);
  29. background-image:-ms-linear-gradient(#444,#222);
  30. background-image:-o-linear-gradient(#444,#222);
  31. background-image:linear-gradient(#444,#222)
  32. }
  33. .ui-overlay-f{background-image:none;border-width:0}
  34. .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}
  35. .ui-body-f .ui-link-inherit{color:#fff}
  36. .ui-body-f .ui-link{color:#2489ce;font-weight:700}
  37. .ui-body-f .ui-link:visited{color:#2489ce}
  38. .ui-body-f .ui-link:hover{color:#2489ce}
  39. .ui-body-f .ui-link:active{color:#2489ce}

发表评论

表情:
评论列表 (有 0 条评论,214人围观)

还没有评论,来说两句吧...

相关阅读

    相关 JqueryMobile页面布局

    最近公司的一个项目需要设计到移动端的页面,网上查了一下JqueryMobile是一个不错的移动端的框架,但是之前又没有接触过只有网上查找一些资料学习,顺便就把我学习的过程记录一