zoukankan      html  css  js  c++  java
  • 动态设置bootstrapswitch状态

    checkbox的html

    <input type="checkbox" name="mySwitch" id="mySwitch">

    引用bootstrap-switch的css和js

    <link href="~/Content/bootstrap-switsh/bootstrap-switch.css" rel="stylesheet" />
     <script src="~/Content/js/jquery/jquery-2.1.1.min.js"></script>@*jquery有一定的版本要求,版本太低可能会让bootstrapswitch事件无法应用*@
     <script src="~/Content/bootstrap-switsh/bootstrap-switch.js"></script>
    

      

    动态设置某个checkbox开关控制状态  

    function load() {  
         //获取控件初始状态window.parent.Warn_Start为false或者true
        var r = window.parent.Warn_Start
        //有则销毁(Destroy)
        $('#mySwitch').bootstrapSwitch('destroy');//定义按钮刷新时可添加,否则可以不加
        //重新加载
        $('#mySwitch').bootstrapSwitch({
                onText: "启动",
                offText: "停止",
                onColor: "success",
                offColor: "info",
                size: "small",
                state: r,
                onSwitchChange: function (event, state) {
                    window.parent.Warn_Start = state;
              var $el = $(event.el)
              , value = event.value;
              console.log(event, $el, value);
                    if (state == true) {
                        Msg.notifySuccess("已启动");
                    } else {
                        Msg.notifySuccess("已关闭");
                    }
                }
    
            })
    }
  • 相关阅读:
    2879. [NOI2012]美食节【费用流】
    luogu P1012 拼数
    luogu cover
    luogu cogs . [NOIP2003] 传染病控制 WA(1/2)
    luogu P1340 兽径管理 WA
    luogu P1342 请柬
    HTML学习笔记二
    HTML学习笔记一
    arr.sort()
    编写函数实现随机产生指定范围的整数的功能
  • 原文地址:https://www.cnblogs.com/Loners/p/10297990.html
Copyright © 2011-2022 走看看