switchery widget: a plurality of buttons for switching jquery

A single button can refer to this link https://blog.csdn.net/u012233776/article/details/53305846

When multiple buttons,

html in which want to operate this button on and off

<div class="form-group">    <label class="col-sm-3 control-label">付费用户2</label>    <div class="col-sm-8">        <input type="checkbox" name="ss" value="1" class="js-switch test" />    </div></div><!--<div class="hr-line-dashed"></div>-->

js

/ * * 
         * Function switching switch Switchery switchElement Switchery objects, checkedBool checked state 
         * / 
        function setSwitchery (switchElement, checkedBool) {
             IF ((checkedBool &&! SwitchElement.isChecked ()) || (! && checkedBool switchElement.isChecked ()) ) { 
                switchElement.setPosition ( to true ); 
                switchElement.handleOnchange ( to true ); 
            } 
        } 
            
        // switch button initialization 
        var switchery = [];
         var the elems = document.querySelectorAll ( 'switch-JS.' );
         for ( var i = 0; i < elems.length; i++) {
            switchery[i] = new Switchery(elems[i]);
        }

Now we need to get the index of the need to switch dom

var js_switch_index = $('.js-switch').index($('.js-switch.test'));
setSwitchery(switchery[js_switch_index], true);//开启
setSwitchery(switchery[js_switch_index], false);//关闭

 

Guess you like

Origin www.cnblogs.com/init-007/p/11204236.html