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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM