jQuery and radio button groups

后端 未结 3 1901
南旧
南旧 2020-12-06 00:56

In jQuery, I\'d like to select all groups of radio buttons where there are no buttons checked.

Or, is there a way in which I can select all radio button groups and i

3条回答
  •  猫巷女王i
    2020-12-06 01:26

    Support for multiple groups and pre-checked.

    $('input').click(function() {
        var $t = $(event.target);
        if ($t.hasClass('checked')) $t.removeAttr('checked');
        else $('input[type="radio"][name="' + $t.prop('name') + '"]').not($t).removeClass('checked');
        $t.toggleClass('checked');
    }).filter(':checked').addClass('checked');​
    

    ```

    Proof: http://jsfiddle.net/abrkn/PGW2Z/

提交回复
热议问题