bootstrap switch開關組件使用方法詳解
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:http://www.bootstrap-switch.org/examples.html
常用的屬性
size:開關大小。可選值有'mini', 'small', 'normal', 'large'
onColor:開關中開按鈕的顏色??蛇x值有'primary', 'info', 'success', 'warning', 'danger', 'default'
offColor:開關中關按鈕的顏色??蛇x值'primary', 'info', 'success', 'warning', 'danger', 'default'
onText:開關中開按鈕的文本,默認是“ON”。
offText:開關中關按鈕的文本,默認是“OFF”。
onInit:初始化組件的事件。
onSwitchChange:開關變化時的事件。


以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript高仿支付寶倒計時頁面及代碼實現(xiàn)
在支付寶上我們經(jīng)常會見到支付寶倒計時功能,倒計時應用非常廣泛,下文給大家介紹js制作支付寶倒計時功能,但是里面涉及到,倒計時,彈框,以及字體圖的相關知識,感興趣的朋友一起看看吧2016-10-10
Webpack學習之動態(tài)import原理及源碼分析
這篇文章主要為大家介紹了Webpack學習之動態(tài)import原理及源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04
javascript獲取select的當前值示例代碼(兼容IE/Firefox/Opera/Chrome)
本篇文章主要介紹了javascript獲取select的當前值示例代碼(兼容IE/Firefox/Opera/Chrome) 需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12
使用JavaScript動態(tài)設置樣式實現(xiàn)代碼及演示動畫
使用onmouseover和onmouseout事件實現(xiàn)不同的效果而且是使用js動態(tài)實現(xiàn),本文有利于鞏固你js與css方面的知識,感興趣的你可以了解下哦,希望本文對你有所幫助2013-01-01

