Jquery if checkbox is checked Bootstrap switch

后端 未结 6 1640
情话喂你
情话喂你 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:44

    $('#uho').attr('checked') will return undefined. you can use $('#uho:checkbox:checked').length property to check if checkbox is checked or not. Try this snippet:

     if ($('#uho:checkbox:checked').length > 0) {
            $.cookie("typpaliva", "Diesel");
       }
       else {
            $.cookie("typpaliva", "Benzin");
       }
    

提交回复
热议问题