Bootstrap 表单输入 (更多)

静态控件

如果需要在水平表单中的表单标签旁边插入 纯文本,请在 <p> 元素上使用 .form-control-static 类:

实例
  1. <form class="form-horizontal">
  2. <div class="form-group">
  3. <label class="control-label col-sm-2">Email:</label>
  4. <div class="col-sm-10">
  5. <p class="form-control-static">someone@example.com</p>
  6. </div>
  7. </div>
  8. </form>

Bootstrap 输入组

.input-group 类是一个容器,通过在其前面或后面添加图标、文本或按钮作为 "帮助文本" 来增强输入。

.input-group-addon 类在输入字段旁边附加一个图标或帮助文本。


Text
实例
  1. <form>
  2. <div class="input-group">
  3. <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
  4. <input id="email" type="text" class="form-control" name="email" placeholder="Email">
  5. </div>
  6. <div class="input-group">
  7. <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
  8. <input id="password" type="password" class="form-control" name="password" placeholder="Password">
  9. </div>
  10. <div class="input-group">
  11. <span class="input-group-addon">Text</span>
  12. <input id="msg" type="text" class="form-control" name="msg" placeholder="Additional Info">
  13. </div>
  14. </form>

.input-group-btn 在输入旁边附加一个按钮。它搜索栏一起使用:

实例
  1. <form>
  2. <div class="input-group">
  3. <input type="text" class="form-control" placeholder="Search">
  4. <div class="input-group-btn">
  5. <button class="btn btn-default" type="submit">
  6. <i class="glyphicon glyphicon-search"></i>
  7. </button>
  8. </div>
  9. </div>
  10. </form>

Bootstrap 表单控件状态


  • 聚焦 input - 被聚焦的输入框边框增加阴影效果
  • 禁用 input - 添加 disabled 属性以禁用输入框
  • 禁用 fieldset - 给 fieldset 元素添加 disabled 属性来禁用里面的所有控件
  • 只读 input - 向输入添加 readonly 只读属性以防止用户输入
  • 验证状态 - Bootstrap 包含了 error(错误), warning(警告), 和 success(成功)的验证样式, 需要向其父元素添加 .has-warning, .has-error, 或者 .has-success
  • 图标 - 您可以使用 has-feedback 类和图标来添加反馈图标
  • 隐藏标签 - 添加 .sr-only 来隐藏标签

下面的实例以 水平表单 的样式演示了上面的一些表单控件状态:

实例
  1. <form class="form-horizontal">
  2. <div class="form-group">
  3. <label class="col-sm-2 control-label">Focused</label>
  4. <div class="col-sm-10">
  5. <input class="form-control" id="focusedInput" type="text" value="Click to focus">
  6. </div>
  7. </div>
  8. <div class="form-group">
  9. <label for="disabledInput" class="col-sm-2 control-label">Disabled</label>
  10. <div class="col-sm-10">
  11. <input class="form-control" id="disabledInput" type="text" disabled>
  12. </div>
  13. </div>
  14. <fieldset disabled>
  15. <div class="form-group">
  16. <label for="disabledTextInput" class="col-sm-2 control-label">Fieldset disabled</label>
  17. <div class="col-sm-10">
  18. <input type="text" id="disabledTextInput" class="form-control">
  19. </div>
  20. </div>
  21. <div class="form-group">
  22. <label for="disabledSelect" class="col-sm-2 control-label"></label>
  23. <div class="col-sm-10">
  24. <select id="disabledSelect" class="form-control">
  25. <option>Disabled select</option>
  26. </select>
  27. </div>
  28. </div>
  29. </fieldset>
  30. <div class="form-group has-success has-feedback">
  31. <label class="col-sm-2 control-label" for="inputSuccess">
  32. Input with success and icon</label>
  33. <div class="col-sm-10">
  34. <input type="text" class="form-control" id="inputSuccess">
  35. <span class="glyphicon glyphicon-ok form-control-feedback"></span>
  36. </div>
  37. </div>
  38. <div class="form-group has-warning has-feedback">
  39. <label class="col-sm-2 control-label" for="inputWarning">
  40. Input with warning and icon</label>
  41. <div class="col-sm-10">
  42. <input type="text" class="form-control" id="inputWarning">
  43. <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
  44. </div>
  45. </div>
  46. <div class="form-group has-error has-feedback">
  47. <label class="col-sm-2 control-label" for="inputError">
  48. Input with error and icon</label>
  49. <div class="col-sm-10">
  50. <input type="text" class="form-control" id="inputError">
  51. <span class="glyphicon glyphicon-remove form-control-feedback"></span>
  52. </div>
  53. </div>
  54. </form>

下面是 内联表单 中一些表单控件状态的示例:

实例
  1. <form class="form-inline">
  2. <div class="form-group">
  3. <label for="focusedInput">Focused</label>
  4. <input class="form-control" id="focusedInput" type="text">
  5. </div>
  6. <div class="form-group">
  7. <label for="inputPassword">Disabled</label>
  8. <input class="form-control" id="disabledInput" type="text" disabled>
  9. </div>
  10. <div class="form-group has-success has-feedback">
  11. <label for="inputSuccess2">Input with success</label>
  12. <input type="text" class="form-control" id="inputSuccess2">
  13. <span class="glyphicon glyphicon-ok form-control-feedback"></span>
  14. </div>
  15. <div class="form-group has-warning has-feedback">
  16. <label for="inputWarning2">Input with warning</label>
  17. <input type="text" class="form-control" id="inputWarning2">
  18. <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
  19. </div>
  20. <div class="form-group has-error has-feedback">
  21. <label for="inputError2">Input with error</label>
  22. <input type="text" class="form-control" id="inputError2">
  23. <span class="glyphicon glyphicon-remove form-control-feedback"></span>
  24. </div>
  25. </form>