warn user if all checkboxes are unchecked

后端 未结 5 1647
借酒劲吻你
借酒劲吻你 2021-02-09 00:04

I have a form with a series of checkboxes. I want to warn the user, after they hit submit, if ALL of the checkboxes are unchecked. I\'m using the following code to report all

5条回答
  •  不知归路
    2021-02-09 00:45

    Working Demo : http://jsfiddle.net/MrkfW/

    Try this: using .change api as well so it keep the track :)

    API: http://api.jquery.com/change/

    $("input[type='checkbox'][id^=leg_rider]").change(function(){
        var a = $("input[type='checkbox'][id^=leg_rider]");
        if(a.length == a.filter(":checked").length){
            alert('all checked');
        } else {
            alert('not all checked');
        }
    });
    

提交回复
热议问题