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

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

my html looks like this

8条回答
  •  猫巷女王i
    2021-02-07 02:54

    $(":radio").change(function() {
        var names = {};
        $(':radio').each(function() {
            names[$(this).attr('name')] = true;
        });
        var count = 0;
        $.each(names, function() { 
            count++;
        });
        if ($(':radio:checked').length === count) {
            alert("all answered");
        }
    }).change();
    

    Demo: http://jsfiddle.net/yFaAj/15/

提交回复
热议问题