warn user if all checkboxes are unchecked

后端 未结 5 1646
借酒劲吻你
借酒劲吻你 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:20

    Try this:

    My html:

    Option 1
    
    Option 2
    Option 3
    Option 4

    My JQuery Code:

    jQuery(".testall").click(function () {
        if (jQuery(".checkbox:checked").length == 0) { alert("no riders"); }
    });
    

    Live example: http://jsfiddle.net/webwarrior/NJwv4/9/

    This will give you the option to check only certain checkboxes.

    hth, Shaun

提交回复
热议问题