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("已关闭");
                    }
                }
    
            })
    }
  • 相关阅读:
    PowerDesigner通过SQL文件,反向生成模型
    跨域请求设置
    SSO单点登录与登出
    jwt使用
    git概念理解
    Slf4j MDC机制
    ASP.NET Core依赖注入最佳实践,提示&技巧
    EFCore数据库迁移命令整理
    RSA加密的使用
    CocoaPods 安装的第三方删除
  • 原文地址:https://www.cnblogs.com/Loners/p/10297990.html
Copyright © 2011-2022 走看看