当前位置: 移动技术网 > IT编程>开发语言>JavaScript > bootstrap switch开关组件使用方法详解

bootstrap switch开关组件使用方法详解

2017年12月12日  | 移动技术网IT编程  | 我要评论

bootstrap中文网上有这么一个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源码地址:

bootstrap-switch文档以及demo:

常用的属性

size:开关大小。可选值有'mini', 'small', 'normal', 'large'
oncolor:开关中开按钮的颜色。可选值有'primary', 'info', 'success', 'warning', 'danger', 'default'
offcolor:开关中关按钮的颜色。可选值'primary', 'info', 'success', 'warning', 'danger', 'default'
ontext:开关中开按钮的文本,默认是“on”。
offtext:开关中关按钮的文本,默认是“off”。
oninit:初始化组件的事件。
onswitchchange:开关变化时的事件。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网