bootstrap 的开关。

引入相关文件:

<link href="https://cdn.bootcss.com/bootstrap-switch/4.0.0-alpha.1/css/bootstrap-switch.min.css" rel="stylesheet">

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>

<script src="https://cdn.bootcss.com/bootstrap-switch/4.0.0-alpha.1/js/bootstrap-switch.min.js"></script>

HTML代码:

<input type="checkbox" name="useState"/>

JavaScript代码:

$("[name='useState']").bootstrapSwitch({
                    size:"large",
                    onText:"启用",
                    offText:"禁用",
                    onColor:"success",
                    onSwitchChange:function(event,state){
                        if(state==true){
                            $(this).val("2");
                        }else{
                            $(this).val("1"); // 禁用
                        }
                    }
                });

设置开或者关:

$('[name="useState"]').bootstrapSwitch("state", true);
// true 为 开,false 为 关

 

参考链接

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2021-07-24
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-08
  • 2021-10-08
  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案