bootstrap學習筆記3:bootstrap常用組件

來源:互聯網
上載者:User
1、表徵圖:

    <h3>表徵圖</h3>       <span class="glyphicon glyphicon-home"></span>    <span class="glyphicon glyphicon-signal"></span>    <span class="glyphicon glyphicon-cog"></span>    <span class="glyphicon glyphicon-apple"></span>    <span class="glyphicon glyphicon-trash"></span>    <span class="glyphicon glyphicon-play-circle"></span>    <span class="glyphicon glyphicon-headphones"></span>


2、按鈕:

    <h3>按鈕</h3>    <button type="button" class="btn btn-default">按鈕</button>    <button type="button" class="btn btn-primary">primary</button>    <button type="button" class="btn btn-success">success</button>    <button type="button" class="btn btn-info">info</button>    <button type="button" class="btn btn-warning">warning</button>    <button type="button" class="btn btn-danger">danger</button>




3、按鈕尺寸:
    <h3>按鈕尺寸</h3>    <button type="button" class="btn btn-default">按鈕</button>    <button type="button" class="btn btn-primary btn-lg">primary</button>    <button type="button" class="btn btn-success btn-sm">success</button>    <button type="button" class="btn btn-info btn-xs">info</button>

4、把表徵圖顯示在按鈕裡:
    <h3>把表徵圖顯示在按鈕裡</h3>    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-home"></span>  按鈕</button>



5、下拉式功能表:
<div class="dropdown">        <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">            <span id="dropdown-title">菜單一</span>            <span class="caret"></span>        </button>        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">            <li><a href="#" class="dropdown-item">菜單一</a></li>            <li><a href="#" class="dropdown-item">菜單二</a></li>            <li><a href="#" class="dropdown-item">菜單三</a></li>        </ul>    </div>

互動:監聽每個菜單的點擊事件,點擊之後在title顯示當前菜單
        $('.dropdown-item').click(function () {            $('#dropdown-title').text($(this).text());        });



6、輸入框:
    <h3>輸入框</h3>    <div class="input-group">      <span class="glyphicon glyphicon-user"></span>      <input type="text" placeholder="username">    </div>    <div class="input-group">      <span class="glyphicon glyphicon-lock"></span>      <input type="password" placeholder="password">    </div>



7、導覽列:
    <h3>導覽列</h3>    <nav class="navbar navbar-inverse navbar-fixed-top">        <div id="navbar" class="navbar-collapse collapse">          <ul class="nav navbar-nav">            <li class="active"><a href="#">Home</a></li>            <li><a href="#about">About</a></li>            <li><a href="#contact">Contact</a></li>            <li class="dropdown">              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>              <ul class="dropdown-menu" role="menu">                <li><a href="#">Action</a></li>                <li><a href="#">Another action</a></li>                <li class="divider"></li>                <li class="dropdown-header">Nav header</li>                <li><a href="#">Separated link</a></li>              </ul>            </li>          </ul>        </div><!--/.nav-collapse -->      </div>    </nav>


8、表單:
    <h3>表單</h3>    <form>    <div class="form-group">      <span class="glyphicon glyphicon-user"></span>      <input type="email" id="exampleInputEmail1" placeholder="Enter email">    </div>    <div class="form-group">      <span class="glyphicon glyphicon-lock"></span>      <input type="password" id="exampleInputPassword1" placeholder="Password">    </div>    <div class="form-group">      <label for="exampleInputFile">File input</label>      <input type="file" id="exampleInputFile">      <p class="help-block">Example block-level help text here.</p>    </div>    <div class="checkbox">      <label>        <input type="checkbox"> Check me out      </label>    </div>    <button type="submit" class="btn btn-default">Submit</button>  </form>



9、警告框:
    <h3>警告框</h3>    <div class="alert alert-warning alert-dismissible" role="alert">       <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>       <strong>Warning!</strong> Better check yourself, you're not looking too good.    </div>    <div class="alert alert-success" role="alert">        <a href="#" class="alert-link">success!</a>    </div>    <div class="alert alert-info" role="alert">        <a href="#" class="alert-link">info!</a>    </div>    <div class="alert alert-warning" role="alert">        <a href="#" class="alert-link">warning!</a>    </div>    <div class="alert alert-danger" role="alert">        <a href="#" class="alert-link">danger!</a>    </div>



10、進度條:
    <h3>進度條</h3>    <div class="progress">      <div class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width: 60%;">        70%      </div>    </div>


11、靠右排列 一般我們是用float:right來實現向右浮動的功能的,但是這裡面右涉及了清除浮動、調整右邊的margin、上下的margin等等問題,在bootstrap當然要用他的方法,只要添加一個class:pull-right就可以解決:
<span style="font-size: 30px;">item1</span><div class="pull-right">item2</div>

這第一行是要跟第二行在一個水平線上的,所以第一行不能用<h1>之類的,因為這種元素內建換行功能。
12、tab的使用 tab可以方便的在一個頁面裡面切換顯示的內容,bootstrap的tab使用非常簡單:
    <ul id="myTab" class="nav nav-tabs">        <li role="presentation" class="active"><a href="#tab1" data-toggle="tab">tab1</a></li>        <li role="presentation"><a href="#tab2" data-toggle="tab">tab2</a></li>        <li role="presentation"><a href="#tab3" data-toggle="tab">tab3</a></li>    </ul>    <span>這是寶貝管理頁面</span>    <div id="myTabContent" class="tab-content">        <div id="tab1" class="tab-pane active">            <p>這是tab1</p>        </div>        <div id="tab2" class="tab-pane">            <p>這是tab2</p>        </div>        <div id="tab3" class="tab-pane">            <p>這是tab3</p>        </div>    </div>

在js可以方便的捕捉tab的切換,並做出相應的改變,比如當第二個頁面是載入一些資料,那麼我等到切換到第二個頁面我再去載入:
        $('a[data-toggle="tab"]').on('shown.bs.tab',function (e) {            var activeTab = $(e.target).text();            alert(activeTab);        });

13、bootstrap-table 一個可以通過ajax請求json資料並產生表格的外掛程式 項目地址: https://github.com/wenzhixin/bootstrap-table


14、通知訊息組件 <1>下載地址: https://github.com/CodeSeven/toastr <2>文檔: http://www.ithao123.cn/content-2414918.html <3>引入: 在下載的檔案裡找到build檔案夾,引入裡面的toastr.min.js和toastr.css <4>使用: 此提示訊息預設是顯示在瀏覽器的右上方,我們可以在初始化裡面改為頂部置中顯示:
        toastr.options.positionClass = 'toast-top-center';//顯示位置

位置顯示的設定有如下選項:
toast-top-righttoast-botton-righttoash-bottom-lefttoast-top-lefttoast-top-full-width 這個是在網頁頂端,寬度鋪滿整個螢幕toast-bottom-full-widthtoast-top-center頂端中間toast-bottom-center

然後在我們需要顯示的時候這樣調用就行了:
toastr.success('提交資料成功');toastr.error('Error');toastr.warning('只能選擇一行進行編輯');toastr.info('info');


15、ajax請求
按鈕:
                <button class="btn btn-link">                    換個密碼                </button>

js:
    $('.btn').on('click',function () {        $.post('xxx')            .done(function (result) {                var json = ajaxResultShow(result);                if (json.result_code == 0)                    $('#pwdId').text(json.data1);            })            .fail(function () {            })            .always(function () {            });    });
16、bootstrap-switch (1)此組件不屬於bootstrap,他需要單獨引入bootstrap-switch.min.js和bootstrap-switch.min.css; (2)下載地址:http://www.bootcss.com/p/bootstrap-switch/ (3)使用方法: 添加架構:
<link href="bootstrap.css" rel="stylesheet"><link href="bootstrap-switch.css" rel="stylesheet"><script src="jquery.js"></script><script src="bootstrap-switch.js"></script>
在html中添加組件:
    <input type="checkbox" name="my-checkbox" checked>
在js中初始化:
        $("[name='my-checkbox']").bootstrapSwitch();
可以在初始化中直接對狀態進行設定:
    $("#isOpenCheckbox").bootstrapSwitch('state',false);
切換狀態:
    $('#isOpenCheckbox').bootstrapSwitch('toggleState');
監聽切換事件:
   $('#isOpenCheckbox').on('switchChange.bootstrapSwitch', function (event,state) {            alert(state);// true || false        });












本文參考了:http://www.cnblogs.com/fnng/p/4446047.html 在此表示感謝。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.