fastadmin如何绑定开关按钮切换事件

我不知道你怎么写的开关,我fastadmin从别处复制了一个开关,写了一段JS监听开关

这是开关代码

<input  id="a-switch" type="hidden" value="0">
<a href="javascript:;" data-toggle="switcher" class="btn-switcher a-switch" data-input-id="a-switch" data-yes="1" data-no="0" >
                <i class="fa fa-toggle-on text-success {eq name="$row.switch" value="0"}fa-flip-horizontal text-gray{/eq} fa-2x"></i>
</a>

这是监听的JS,我为了方便引用了JQ,你可以写原生js

<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
    $('.a-switch').click(function () {
        var val = $('#a-switch').val();
        if(val == 0){
            // 此处写给你想控制的元素加上 disabled
            console.log(val);
        }else{
            // 此处写给你想控制的元素去掉 disabled
            console.log(val);
        }
    })
</script>

猜你喜欢

转载自www.cnblogs.com/apolloren/p/13369216.html