Bootstrap中的表单控件状态主要有三种:焦点状态,禁用状态,验证状态。

 
一、焦点状态:该状态告诉用户可输入或选择东西
焦点状态通过伪类“:focus”以实现。
bootstrap.css相应源码:
.form-control:focus {
border-color: #66afe9;
outline:; //删除了outline的默认样式
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6); //添加了阴影效果
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
}

使用方法:给控件添加类名“form-control”。

eg:
<input class="form-control" type="text" placeholder="不是焦点状态下效果">
<input class="form-control" type="text" placeholder="焦点状态下效果">
效果图如下所示:(焦点状态下为蓝色边框效果)
焦点状态下,file、radio、checkbox控件的效果与普通的input空间不完全一样,因为bootstrap对它们做了特殊处理。
bootstrap.css相应源码:
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
outline: thin dotted;
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}

二、禁用状态:该状态告诉用户不可以输入或选择东西
禁用状态是通过在表单控件上添加"disabled"属性以实现。
bootstrap.css相应源码:
.form-control[disabled],
.form-control[readonly],
fieldset[disabled] .form-control {
cursor: not-allowed;
background-color: #eee;
opacity:;
}
使用方法:在需要禁用的表单控件上加上"diabled"属性即可。
eg:
<input class="form-control" type="text" placeholder="不是焦点状态下效果">
<input class="form-control" type="text" placeholder="表单已禁用,不能输入" disabled>
效果图如下所示:

说明:禁用状态下控件背景色为灰色,且手型变为不准输入的形状,若表单控件不使用类名"form-control",则禁用的控件只有一个不准输入的手型。
PS:在Bootstrap中,若fieldset设置了"disabled"属性,则整个域都处于被禁用状态。
eg:
 <form role="form">
<fieldset disabled>
<div class="form-group">
<label for="disabledTextInput">禁用的输入框</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="禁止输入">
</div>
<div class="form-group">
<label for="disabledSelect">禁用的下拉框</label>
<select id="disabledSelect" class="form-control">
<option>不可选择</option>
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox">无法选择
</label>
</div>
<button type="submit" class="btnbtn-primary">提交</button>
</fieldset>
</form>
效果如下图所示:

PS:对于一个禁用的域,若legend中有输入框,则此输入框是无法被禁用的。
eg:
 <form role="form">
<fieldset disabled>
<legend><input type="text" class="form-control" placeholder="我没被禁用" /></legend>
<div class="form-group">
<label for="disabledTextInput">禁用的输入框</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="禁止输入">
</div>
<div class="form-group">
<label for="disabledSelect">禁用的下拉框</label>
<select id="disabledSelect" class="form-control">
<option>不可选择</option>
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox">无法选择
</label>
</div>
<button type="submit" class="btnbtn-primary">提交</button>
  </fieldset>
</form>
效果图如下所示:

三、验证状态:该状态告诉用户,他们的操作是否正确

在Bootstrap中提供3种验证状态样式:

① .has-success : 成功状态(绿色)
② .has-error : 错误状态(红色)
③ .has-warning : 警告状态(黄色)
使用方法:在form-group容器上添加对应的状态类名即可。
eg:
 <form role="form">
<div class="form-group has-success">
<label class="control-label" for="inputSuccess1">成功状态</label>
<input type="text" class="form-control" id="inputSuccess1" placeholder="成功状态" >
</div>
<div class="form-group has-warning">
<label class="control-label" for="inputWarning1">警告状态</label>
<input type="text" class="form-control" id="inputWarning1" placeholder="警告状态">
</div>
<div class="form-group has-error">
<label class="control-label" for="inputError1">错误状态</label>
<input type="text" class="form-control" id="inputError1" placeholder="错误状态">
</div>
</form>
说明:从效果可看出,三种样式除了颜色不同外,效果都一样。
在Bootstrap的表单验证中,不同状态会提供不同的icon,如成功是个对号"√",错误是个叉号"×"等。
若想让表单在不同状态下显示对应的icon,则只需在对应状态下添加类名"has-feedback"。
PS:类名"has-feedback"要与"has-error"、"has-warning"、"has-success"配合使用。
eg:
 <form role="form">
<div class="form-group has-success has-feedback">
<label class="control-label" for="inputSuccess">成功状态</label>
<input type="text" class="form-control" id="inputSuccess" placeholder="成功状态" >
<span class="glyphicon glyphicon-ok form-control-feedback"></span>
</div>
<div class="form-group has-warning has-feedback">
<label class="control-label" for="inputWarning">警告状态</label>
<input type="text" class="form-control" id="inputWarning" placeholder="警告状态" >
<span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
  </div>
  <div class="form-group has-error has-feedback">
<label class="control-label" for="inputError">错误状态</label>
<input type="text" class="form-control" id="inputError" placeholder="错误状态" >
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
  </div>
</form>
效果如下所示:

说明:从效果图中可看出,图标都居右。
注:Bootstrap中的图标都是使用@face-face来制作,且必须在表单中添加个span元素来实现。
eg:
<span class="glyphicon glyphicon-remove form-control-feedback"></span>

Bootstrap之表单控件状态的更多相关文章

  1. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:表单控件状态

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Bootstrap的表单控件

    支持的表单控件 Bootstrap 支持最常见的表单控件,主要是 input.textarea.checkbox.radio 和 select. 输入框(Input) 最常见的表单文本字段是输入框 i ...

  3. Bootstrap历练实例:表单控件状态(禁用的字段集fieldset)

    禁用的字段集 fieldset 对 <fieldset> 添加 disabled 属性来禁用 <fieldset> 内的所有控件. <!DOCTYPE html>& ...

  4. Bootstrap历练实例:表单控件状态(禁用)

    禁用的输入框 input 如果您想要禁用一个输入框 input,只需要简单地添加 disabled 属性,这不仅会禁用输入框,还会改变输入框的样式以及当鼠标的指针悬停在元素上时鼠标指针的样式. < ...

  5. Bootstrap历练实例:表单控件状态(焦点)

    输入框焦点 当输入框 input 接收到 :focus 时,输入框的轮廓会被移除,同时应用 box-shadow. <!DOCTYPE html><html><head& ...

  6. Bootstrap CSS 表单

    表单布局 Bootstrap 提供了下列类型的表单布局: 垂直表单(默认) 内联表单 水平表单 垂直或基本表单 基本的表单结构是 Bootstrap 自带的,个别的表单控件自动接收一些全局样式.下面列 ...

  7. bootstrap -- css -- 表单控件

    若干css样式 .form-control { display: block; width: 100%; height: 34px; padding: 6px 12px; font-size: 14p ...

  8. bootstrap之表单

    一.表单布局 向父 <form> 元素添加 role="form". 把标签和控件放在一个带有 class .form-group 的 <div> 中.这是 ...

  9. bootstrap 基础表单

    表单中常见的元素主要包括:文本输入框.下拉选择框.单选按钮.复选按钮.文本域和按钮等.其中每个控件所起的作用都各不相同,而且不同的浏览器对表单控件渲染的风格都各有不同. ☑   LESS版本:对应源文 ...

随机推荐

  1. 扫描仪API接入大全:Twain, WIA 或 两者不具有.[换个思路 春暖花开]

    最近做和扫描仪接入的扫描应用程序,深深感觉到了来自底层设备和WINDOWS协议的恶意.软件专业,对计算机深层次通知机制和协议,以及与之相连接的机器的接入协议和一些参数,当时并木有认真学习和了解,前一阵 ...

  2. Python模拟HttpRequest的方法总结

    Python可以说是爬网的利器,本文主要介绍了一些python来模拟http请求的一些方法和技巧. Python处理请求的类库有两个,urllib,urllib2. 这两个类库并不是一个类库的两个不同 ...

  3. Ajax_04之jQuery中封装的Ajax函数

    1.PHP中json_encode编码规则: PHP索引数组编码为JSON:[...] PHP关联数组编码为JSON:{...}2.jQuery中AJAX封装函数之load: ①使用:$('选择器') ...

  4. Kafka随笔一

    一.KafKa所涉及到的名词概念: 1.    Topic:用于划分Message的逻辑概念,一个Topic可以分布在多个Broker上. 2.    Partition:是Kafka中横向扩展和一切 ...

  5. JS原生基础终结篇 (帅哥)

    闭包 基础    面向对象基础 1.1 闭包 在程序语言中,所谓闭包,是指语法域位于某个特定的区域,具有持续参照(读写)位于该区域内自身范围之外的执行域上的非持久型变量值能力的段落.这些外部执行域的非 ...

  6. 前端:圆图头像制作--border-radius : 100%

    异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html border-radius : 100% border-radius: 6px; ...

  7. Unity 文件读取

    存储: 在程序发布后文件的存放有两种,第一种是打包到Uniyt的资源包中(*.unity3D),第二种就是把文件存放在一个特殊的目录如:StreamingAssets,这个目录的东西Unity不会打包 ...

  8. mpi4py实践

    版权声明:本文为博主原创文章,未经博主允许不得转载. 1.概述 MPI(Message Passing Interface),消息传递接口,是一个标准化和轻便的能够运行在各种各样并行计算机上的消息传递 ...

  9. MySQL学习笔记五:数据类型

    MySQL支持多种数据类型,大致可以分为数值,日期/时间和字符类型. 数值类型 MySQL支持所有标准SQL数值数据类型,包括严格数值数据类型(INTEGER.SMALLINT.DECIMAL和NUM ...

  10. git与svn, tfs等源代码管理器的协同

    简单地说,这三个都是业界知名的源代码管理器.他们是有区别的,根本的区别在于git是分布式源代码管理器(每个本地都有完整的代码,及历史),而svn和tfs是集中式源代码管理器(只有服务器才有完整的历史, ...