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

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

my html looks like this

8条回答
  •  走了就别回头了
    2021-02-07 02:54

    Solution here http://jsfiddle.net/QxdnZ/1/

        var checked = $("#div1 :radio:checked");
        var groups = [];
        $("#div1 :radio").each(function() {
            if (groups.indexOf(this.name) < 0) {
                groups.push(this.name);
            }
        });
        if (groups.length == checked.length) {
            alert('all are checked!');
        }
        else {
            var total = groups.length - checked.length;
            var a = total>1?' groups are ':' group is ';
    
            alert(total + a + 'not selected');
        }
    

提交回复
热议问题