Bootstrap switch checked event?

前端 未结 9 1713
感情败类
感情败类 2021-01-31 14:48

I use this codes for checkbox checked event but it does not work.

css



        
9条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 15:33

    For me this was the only working code (Bootstrap 3.0) :

    $('#my_checkbox').on('change.bootstrapSwitch', function(e) {
        console.log(e.target.checked);
    });
    

    It returns me true or false

    Example with Ajax submission on bootstrap switch change :

    $('#my_checkbox').on('change.bootstrapSwitch', function(e) {
        $.ajax({
            method: 'POST',
            url: '/uri/of/your/page',
            data: {
                'my_checkbox_value': e.target.checked
            },
            dataType: 'json',
            success: function(data){
                console.log(data);
            }
        });
    });
    

提交回复
热议问题