Jquery if checkbox is checked Bootstrap switch

后端 未结 6 1631
情话喂你
情话喂你 2021-01-18 23:13

I use Bootstrap switch plugin to make my checkboxes looks like switch buttons. I need to check if the checkbox is checked in jQuery. I Googled a lot and I tried some advice

6条回答
  •  被撕碎了的回忆
    2021-01-18 23:54

    Based on a comment in the accepted answer, here's how I solved this for a Terms and Conditions checkbox in bootstrap:

    HTML

    Javascript (with jQuery)

    $("#agreeTAC").change(function(){
        var agreed = $(this).is(':checked');
        console.log("agreeTAC value changed and is ", agreed);
        if(agreed === true) { 
           // do 'true' stuff, like enabling a 'Continue' button
        }
        else {
           // do 'false' stuff, like disabling a 'Continue' button
        }
    })
    

提交回复
热议问题