您现在的位置:首页 >> 前端 >> 内容

Bootstrap—表单学习笔记

时间:2016/12/13 9:34:55 点击:

  核心提示:本文知识点写的比较详细还给出了例子,这里总结一下重点方便记忆。strong一、表单布局:/strongstrong1.垂直表单(默认)/strong向父 form 元素添加 role=form。把标签...

本文知识点写的比较详细还给出了例子,这里总结一下重点方便记忆。

<strong>一、表单布局:</strong>
    <strong>1.垂直表单(默认)</strong>
        向父 <form> 元素添加 role="form"。
        把标签和控件放在一个带有 class .form-group 的 <p> 中。这是获取最佳间距所必需的。
        向所有的文本元素 <input>、<textarea> 和 <select> 添加 class .form-control。
        <pre class="brush:sql;"><form action="#" role="form">
        <p class="form-group">
            <lable>姓名:<input class="form-control" type="text"/></lable>
            <lable>性别:<input class="form-control" type="text"/></lable>
        </p>
 </form></pre><br><br><pre class="brush:sql;">  <strong>  2.内联表单</strong>
</pre>        向 <form> 标签添加 class .form-inline        默认情况下,Bootstrap 中的 input、select 和 textarea 有 100% 宽度。在使用内联表单时,您需要在表单控件上设置一个宽度。        使用 class .sr-only,您可以隐藏内联表单的标签。<br><strong> <br>    3.水平表单</strong>        向父 <form> 元素添加 class .form-horizontal。        把标签和控件放在一个带有 class .form-group 的 <p> 中。        向标签添加 class .control-label。<br>  <pre class="brush:sql;"><pre class="brush:sql;"><form action="#" role="form" class="form-horizontal">
        <p class="form-group">
            <lable class="control-label col-lg-2">姓名:</lable>
            <p class=" col-lg-10"><input class="form-control" type="text"/></p>
 
            <lable class="control-label col-lg-2">性别:</lable>
            <p class="col-lg-10"><input class="form-control " type="text"/></p>
        </p>
 </form></pre><br></pre><br><strong></strong><strong></strong><strong>二、支持的表单控件:</strong>    <strong>1.输入框(</strong><strong>Input</strong><strong>)</strong><pre class="brush:sql;"><pre class="brush:sql;"><lable>姓名:<input class="form-control" type="text"/></lable></pre><br></pre><br>    <strong>2.文本框(</strong><strong>Textarea</strong><strong>)</strong>        改变 rows 属性<br><pre class="brush:sql;"><pre class="brush:sql;"><p class="form-group">
        <textarea rows="8" class="form-control">
 
         </textarea>
 
    </p></pre></pre><br><br><strong> 3.复选框(Checkbox)和单选框(Radio</strong><strong>)</strong>        当创建表单时,如果您想让用户从列表中选择若干个选项时,请使用 checkbox。如果您限制用户只能选择一个选项,请使用 radio。        对一系列复选框和单选框使用 .checkbox-inline 或 .radio-inline class,控制它们显示在同一行上。<br><pre class="brush:sql;">            <p class="checkbox-inline">
                <lable class="control-label"><input type="checkbox"/>篮球</lable>
            </p>
            <p class="checkbox-inline">
                <lable class="control-label"><input type="checkbox"/>音乐</lable>
            </p>
            <p class="checkbox-inline">
                <lable class="control-label"><input type="checkbox"/>绘画</lable>
            </p>
            <p class="radio">
                <lable><input type="radio"/>男</lable>
            </p>
            <p class="radio">
                <lable><input type="radio"/>女</lable>
            </p></pre><br><br><br><strong>4.选择框(</strong><strong>Select</strong><strong>)</strong>        使用 <select> 展示列表选项,通常是那些用户很熟悉的选择列表,比如州或者数字。        使用 multiple="multiple" 允许用户选择多个选项。<br><pre class="brush:sql;"><p class="form-group">
                    <select name="" id="" class="form-control" multiple>
                        <option value="">1</option>
                        <option value="">1</option>
                        <option value="">1</option>
                        <option value="">1</option>
                        <option value="">1</option>
                    </select>
                </p></pre><br><br><strong>5.静态控件</strong>        当您需要在一个水平表单内的表单标签后放置纯文本时,请在 <p> 上使用 class .form-control-static。表单控件状态:<br><pre class="brush:sql;"> <p class="form-group">
                    <label class="col-sm-2 control-label">Email</label>
                    <p class="col-sm-10">
                        <p class="form-control-static">email@example.com</p>
                    </p>
                </p></pre><br><br><strong>  6.输入框焦点</strong>        当输入框 input 接收到 :focus 时,输入框的轮廓会被移除,同时应用 box-shadow。    <strong>7.禁用的输入框 </strong><strong>input</strong>        如果您想要禁用一个输入框 input,只需要简单地添加 disabled 属性,这不仅会禁用输入框,        还会改变输入框的样式以及当鼠标的指针悬停在元素上时鼠标指针的样式。<br><pre class="brush:sql;"> <p>
                    <lable>姓名:<input type="text" disabled class="form-control"/></lable>
                </p></pre><br><br><strong>8.禁用的字段集 </strong><strong>fieldset</strong>        对 <fieldset> 添加 disabled 属性来禁用 <fieldset> 内的所有控件。<br><br><strong>9.验证状态</strong>        Bootstrap 包含了错误、警告和成功消息的验证样式。只需要对父元素简单地添加适当的        class(.has-warning、 .has-error 或 .has-success)即可使用验证状态。<br><pre class="brush:sql;"><p class="has-error">
                    <lable class="control-label">
                        姓名:<input type="text" class="form-control" placeholder="has-error"/>
                    </lable>
                </p>
                <p class="has-warning">
                    <lable class="control-label">
                        姓名:<input type="text" class="form-control" placeholder="has-warning"/>
                    </lable>
                </p> 
                <p class="has-success">
                    <lable class="control-label">
                        姓名:<input type="text" class="form-control" placeholder="has-success"/>
         
                    </lable>
                </p></pre><br><br><strong>10.表单控件大小</strong>    分别使用 class .input-lg(或.input-sm) 和 .col-lg-* 来设置表单的高度和宽度<br><pre class="brush:sql;"> <p class="form-group">
                姓名:<input type="text" class="form-control input-lg" placeholder="input-lg"/>
                姓名:<input type="text" class="form-control input-sm" placeholder="input-sm"/>
                姓名:<input type="text" class="form-control " placeholder="normal"/>
            </p></pre><br><br><strong>11.表单帮助文本</strong>    Bootstrap 表单控件可以在输入框 input 上有一个块级帮助文本。    为了添加一个占用整个宽度的内容块,请在 <input> 后使用 .help-block。<br><pre class="brush:sql;"><p class="form-grounp">
                <input type="text"/>
                <span class="help-block">
                    Bootstrap 表单控件可以在输入框 input 上有一个块级帮助文本。
                </span>
            </p></pre><br><br>

 

Tags:BO OO OT TS 
作者:网络 来源:生如夏花 炫至茶靡