Input,用于表单,可以分成“输入型”和“选择型”两种。输入型包括单行文本(文本、数值、电话、密码等)、多行文本;选择型包括下拉选择、单选、多选、开关、日期时间等。在 WeUI 中,表单通常与 Cell 组件配合使用。

    示例代码如下:

    1. <div class="weui-cells__title">单选列表项</div>
    2. <div class="weui-cells weui-cells_radio">
    3. <label class="weui-cell weui-check__label" for="x11">
    4. <div class="weui-cell__bd">
    5. <p>cell standard</p>
    6. </div>
    7. <div class="weui-cell__ft">
    8. <input type="radio" class="weui-check" name="radio1" id="x11">
    9. <span class="weui-icon-checked"></span>
    10. </div>
    11. </label>
    12. <label class="weui-cell weui-check__label" for="x12">
    13.  
    14. <div class="weui-cell__bd">
    15. <p>cell standard</p>
    16. </div>
    17. <div class="weui-cell__ft">
    18. <input type="radio" name="radio1" class="weui-check" id="x12" checked="checked">
    19. <span class="weui-icon-checked"></span>
    20. </div>
    21. </label>
    22. <a href="javascript:void(0);" class="weui-cell weui-cell_link">
    23. <div class="weui-cell__bd">添加更多</div>
    24. </a>
    25. </div>
    26. <div class="weui-cells__title">复选列表项</div>
    27. <div class="weui-cells weui-cells_checkbox">
    28. <label class="weui-cell weui-check__label" for="s11">
    29. <div class="weui-cell__hd">
    30. <input type="checkbox" class="weui-check" name="checkbox1" id="s11" checked="checked">
    31. <i class="weui-icon-checked"></i>
    32. </div>
    33. <div class="weui-cell__bd">
    34. <p>standard is dealt for u.</p>
    35. </div>
    36. </label>
    37. <label class="weui-cell weui-check__label" for="s12">
    38. <div class="weui-cell__hd">
    39. <input type="checkbox" name="checkbox1" class="weui-check" id="s12">
    40. <i class="weui-icon-checked"></i>
    41. </div>
    42. <div class="weui-cell__bd">
    43. <p>standard is dealicient for u.</p>
    44. </div>
    45. </label>
    46. <a href="javascript:void(0);" class="weui-cell weui-cell_link">
    47. <div class="weui-cell__bd">添加更多</div>
    48. </a>
    49. </div>
    50.  
    51. <div class="weui-cells__title">表单</div>
    52. <div class="weui-cells weui-cells_form">
    53. <div class="weui-cell">
    54. <div class="weui-cell__hd"><label class="weui-label">qq</label></div>
    55. <div class="weui-cell__bd">
    56. <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入qq号"/>
    57. </div>
    58. </div>
    59. <div class="weui-cell weui-cell_vcode">
    60. <div class="weui-cell__hd">
    61. <label class="weui-label">手机号</label>
    62. </div>
    63. <div class="weui-cell__bd">
    64. <input class="weui-input" type="tel" placeholder="请输入手机号">
    65. </div>
    66. <div class="weui-cell__ft">
    67. <a href="javascript:;" class="weui-vcode-btn">获取验证码</a>
    68. </div>
    69. </div>
    70. <div class="weui-cell">
    71. <div class="weui-cell__hd"><label for="" class="weui-label">日期</label></div>
    72. <div class="weui-cell__bd">
    73. <input class="weui-input" type="date" value=""/>
    74. </div>
    75. </div>
    76. <div class="weui-cell">
    77. <div class="weui-cell__hd"><label for="" class="weui-label">时间</label></div>
    78. <div class="weui-cell__bd">
    79. <input class="weui-input" type="datetime-local" value="" placeholder=""/>
    80. </div>
    81. </div>
    82. <div class="weui-cell weui-cell_vcode">
    83. <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
    84. <div class="weui-cell__bd">
    85. <input class="weui-input" type="number" placeholder="请输入验证码"/>
    86. </div>
    87. <div class="weui-cell__ft">
    88. <img class="weui-vcode-img" src="./images/vcode.jpg" />
    89. </div>
    90. </div>
    91. </div>
    92. <div class="weui-cells__tips">底部说明文字底部说明文字</div>
    93.  
    94. <div class="weui-cells__title">表单报错</div>
    95. <div class="weui-cells weui-cells_form">
    96. <div class="weui-cell weui-cell_warn">
    97. <div class="weui-cell__hd"><label for="" class="weui-label">卡号</label></div>
    98. <div class="weui-cell__bd">
    99. <input class="weui-input" type="number" pattern="[0-9]*" value="weui input error" placeholder="请输入卡号"/>
    100. </div>
    101. <div class="weui-cell__ft">
    102. <i class="weui-icon-warn"></i>
    103. </div>
    104. </div>
    105. </div>
    106.  
    107.  
    108. <div class="weui-cells__title">开关</div>
    109. <div class="weui-cells weui-cells_form">
    110. <div class="weui-cell weui-cell_switch">
    111. <div class="weui-cell__bd">标题文字</div>
    112. <div class="weui-cell__ft">
    113. <input class="weui-switch" type="checkbox"/>
    114. </div>
    115. </div>
    116. </div>
    117.  
    118. <div class="weui-cells__title">文本框</div>
    119. <div class="weui-cells">
    120. <div class="weui-cell">
    121. <div class="weui-cell__bd">
    122. <input class="weui-input" type="text" placeholder="请输入文本"/>
    123. </div>
    124. </div>
    125. </div>
    126.  
    127. <div class="weui-cells__title">文本域</div>
    128. <div class="weui-cells weui-cells_form">
    129. <div class="weui-cell">
    130. <div class="weui-cell__bd">
    131. <textarea class="weui-textarea" placeholder="请输入文本" rows="3"></textarea>
    132. <div class="weui-textarea-counter"><span>0</span>/200</div>
    133. </div>
    134. </div>
    135. </div>
    136.  
    137. <div class="weui-cells__title">选择</div>
    138. <div class="weui-cells">
    139.  
    140. <div class="weui-cell weui-cell_select weui-cell_select-before">
    141. <div class="weui-cell__hd">
    142. <select class="weui-select" name="select2">
    143. <option value="1">+86</option>
    144. <option value="2">+80</option>
    145. <option value="3">+84</option>
    146. <option value="4">+87</option>
    147. </select>
    148. </div>
    149. <div class="weui-cell__bd">
    150. <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入号码"/>
    151. </div>
    152. </div>
    153. </div>
    154. <div class="weui-cells__title">选择</div>
    155. <div class="weui-cells">
    156. <div class="weui-cell weui-cell_select">
    157. <div class="weui-cell__bd">
    158. <select class="weui-select" name="select1">
    159. <option selected="" value="1">微信号</option>
    160. <option value="2">QQ号</option>
    161. <option value="3">Email</option>
    162. </select>
    163. </div>
    164. </div>
    165. <div class="weui-cell weui-cell_select weui-cell_select-after">
    166. <div class="weui-cell__hd">
    167. <label for="" class="weui-label">国家/地区</label>
    168. </div>
    169. <div class="weui-cell__bd">
    170. <select class="weui-select" name="select2">
    171. <option value="1">中国</option>
    172. <option value="2">美国</option>
    173. <option value="3">英国</option>
    174. </select>
    175. </div>
    176. </div>
    177. </div>
    178.  
    179. <label for="weuiAgree" class="weui-agree">
    180. <input id="weuiAgree" type="checkbox" class="weui-agree__checkbox">
    181. <span class="weui-agree__text">
    182. 阅读并同意<a href="javascript:void(0);">《相关条款》</a>
    183. </span>
    184. </label>
    185.  
    186. <div class="weui-btn-area">
    187. <a class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips">确定</a>
    188. </div>

    原文: https://github.com/Tencent/weui/wiki/Input