jquery: how to check if all radio buttons in a div are selected

前端 未结 8 1097
一向
一向 2021-02-07 02:13

my html looks like this

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 02:50

    Restructure your HTML slightly - wrap each radio group in (say) a div. Then you can just do something like this to validate the form when the user submits it:

    if ($('div:not(:has(:radio:checked))').length) {
        alert("At least one group is blank");
    }
    

    Of course this can be tweaked in various ways to suit your HTML. The idea was from Find all radio groups which haven't been selected

提交回复
热议问题