国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

Bootstrap 按鈕(Button)插件

2022-05-21 15:21 更新

Bootstrap 按鈕(Button)插件

按鈕(Button)在 Bootstrap 按鈕 一章中介紹過。通過按鈕(Button)插件,您可以添加進一些交互,比如控制按鈕狀態(tài),或者為其他組件(如工具欄)創(chuàng)建按鈕組。

如果您想要單獨引用該插件的功能,那么您需要引用 button.js?;蛘?,正如 Bootstrap 插件概覽 一章中所提到,您可以引用 bootstrap.js 或壓縮版的 bootstrap.min.js

加載狀態(tài)

如需向按鈕添加加載狀態(tài),只需要簡單地向 button 元素添加 data-loading-text="Loading..." 作為其屬性即可,如下面實例所示:

<!DOCTYPE html><html><head>
   <title>Bootstrap 實例 - 按鈕(Button)插件加載狀態(tài)</title>
   <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
   <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
   <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script></head><body><button id="fat-btn" class="btn btn-primary" data-loading-text="Loading..." 
   type="button"> 加載狀態(tài)</button><script>
   $(function() { 
      $(".btn").click(function(){
         $(this).button('loading').delay(1000).queue(function() {
           // $(this).button('reset');
         });        
      });
   });  </script></body></html>

結(jié)果如下所示:

按鈕(Button)插件加載狀態(tài)

單個切換

如需激活單個按鈕的切換(即改變按鈕的正常狀態(tài)為按壓狀態(tài),反之亦然),只需向 button 元素添加 data-toggle="button" 作為其屬性即可,如下面實例所示:

<!DOCTYPE html><html><head>
   <title>Bootstrap 實例 - 按鈕(Button)插件單個切換</title>
   <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
   <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
   <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script></head><body><button type="button" class="btn btn-primary" 
   data-toggle="button"> 單個切換</button></body></html>

結(jié)果如下所示:

按鈕(Button)插件單個切換

復選框(Checkbox)

您可以創(chuàng)建復選框組,并通過向 btn-group 添加 data 屬性 data-toggle="buttons" 來添加復選框組的切換。

<!DOCTYPE html><html><head>
   <title>Bootstrap 實例 - 按鈕(Button)插件復選框</title>
   <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
   <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
   <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script></head><body><div class="btn-group" data-toggle="buttons">
   <label class="btn btn-primary">
      <input type="checkbox"> 選項 1   </label>
   <label class="btn btn-primary">
      <input type="checkbox"> 選項 2   </label>
   <label class="btn btn-primary">
      <input type="checkbox"> 選項 3   </label></div></body></html>

結(jié)果如下所示:

按鈕(Button)插件復選框

單選按鈕(Radio)

類似地,您可以創(chuàng)建單選按鈕組,并通過向 btn-group 添加 data 屬性 data-toggle="buttons" 來添加單選按鈕組的切換。

<!DOCTYPE html><html><head>
   <title>Bootstrap 實例 - 按鈕(Button)插件單選按鈕</title>
   <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
   <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
   <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script></head><body><div class="btn-group" data-toggle="buttons">
   <label class="btn btn-primary">
      <input type="radio" name="options" id="option1"> 選項 1   </label>
   <label class="btn btn-primary">
      <input type="radio" name="options" id="option2"> 選項 2   </label>
   <label class="btn btn-primary">
      <input type="radio" name="options" id="option3"> 選項 3   </label></div>	</body></html>

結(jié)果如下所示:

按鈕(Button)插件單選按鈕

用法

您可以 通過 JavaScript 啟用按鈕(Button)插件,如下所示:

$('.btn').button()

選項

沒有選項。

方法

下面是一些按鈕(Button)插件中有用的方法:

方法描述實例
button('toggle')切換按壓狀態(tài)。賦予按鈕被激活的外觀。您可以使用 data-toggle 屬性啟用按鈕的自動切換。
$().button('toggle')
.button('loading')當加載時,按鈕是禁用的,且文本變?yōu)?button 元素的 data-loading-text 屬性的值。
$().button('loading')
.button('reset')重置按鈕狀態(tài),文本內(nèi)容恢復為最初的內(nèi)容。當您想要把按鈕返回為原始的狀態(tài)時,該方法非常有用。
$().button('reset')
.button(string)該方法中的字符串是指由用戶聲明的任何字符串。使用該方法,重置按鈕狀態(tài),并添加新的內(nèi)容。
$().button(string)

實例

下面的實例演示了上面方法的用法:

<!DOCTYPE html><html><head>
   <title>Bootstrap 實例 - 按鈕(Button)插件方法</title>
   <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
   <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
   <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script></head><body><h2>點擊每個按鈕查看方法效果</h2><h4>演示 .button('toggle') 方法</h4><div id="myButtons1" class="bs-example">
   <button type="button" class="btn btn-primary">原始</button></div><h4>演示 .button('loading') 方法</h4><div id="myButtons2" class="bs-example">
   <button type="button" class="btn btn-primary" 
      data-loading-text="Loading...">原始   </button></div><h4>演示 .button('reset') 方法</h4><div id="myButtons3" class="bs-example">
   <button type="button" class="btn btn-primary" 
      data-loading-text="Loading...">原始   </button></div><h4>演示 .button(string) 方法</h4><button type="button" class="btn btn-primary" id="myButton4" 
   data-complete-text="Loading finished">請點擊我</button><script type="text/javascript">
   $(function () {
      $("#myButtons1 .btn").click(function(){
         $(this).button('toggle');
      });
   });
   $(function() { 
      $("#myButtons2 .btn").click(function(){
         $(this).button('loading').delay(1000).queue(function() {
         });        
      });
   });   
   $(function() { 
      $("#myButtons3 .btn").click(function(){
         $(this).button('loading').delay(1000).queue(function() {
            $(this).button('reset');
         });        
      });
   });  
   $(function() { 
      $("#myButton4").click(function(){
         $(this).button('loading').delay(1000).queue(function() {
            $(this).button('complete');
         });        
      });
   }); </script> </body></html>

結(jié)果如下所示:

按鈕(Button)插件方法
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號