bootstrap中文網(wǎng)上有這么一個bootstrap-switch組件,很實用,看demo學習并記錄一下。

<!DOCTYPE html> <html>   <head>     <meta charset=utf-8>     <meta name=description content="">     <meta name=viewport content="width=device-width, initial-scale=1">     <title></title>     <link href="css/bootstrap.min.css" rel="external nofollow" rel="stylesheet" />     <link href="css/bootstrap-switch.min.css" rel="external nofollow" rel="stylesheet" />      <script src="js/jquery/jquery.1.11.3.min.js"></script>      <script src="js/bootstrap.min.js"></script>     <script src="js/bootstrap-switch.min.js"></script>    </head>   <body>      <input name="status" type="checkbox" data-size="small">       <script type="text/javascript">       $('[name="status"]').bootstrapSwitch({        onText:"啟動",        offText:"停止",        onColor:"success",        offColor:"info",        size:"small",      onSwitchChange:function(event,state){        if(state==true){          alert('已打開');        }else{          alert('已關閉');        }      }          })       </script>   </body> </html> Bootstrap-Switch源碼地址:https://github.com/nostalgiaz/bootstrap-switch
Bootstrap-Switch文檔以及Demo:onColor:開關中開按鈕的顏色。可選值有'primary', 'info', 'success', 'warning', 'danger', 'default'
offColor:開關中關按鈕的顏色。可選值'primary', 'info', 'success', 'warning', 'danger', 'default'
onText:開關中開按鈕的文本,默認是“ON”。
offText:開關中關按鈕的文本,默認是“OFF”。
onInit:初始化組件的事件。
onSwitchChange:開關變化時的事件。


以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答