在 jquery 的数组中检查收音机

2022-01-21 00:00:00 radio-button forms jquery html

我得到了下一个 html 代码,我想得到选中的单选按钮数组:

I got the next html code and i want to get the array of checked radio buttons:

    <tr>
    <td>¿Cómo te llamas?</td>

    <td><input class="radio" type="radio" name="respuesta1" value="female"> Pablo</td>
    <td><input class="radio" type="radio" name="respuesta1" value="female"> Christian</td>
    <td><input class="radio" type="radio" name="respuesta1" value="female"> Alberto</td>


    </tr>

    <tr>
    <td>¿Cuánto es 2 + 2?</td>


    <td><input class="radio" type="radio" name="respuesta2" value="female"> 2</td>
    <td><input class="radio" type="radio" name="respuesta2" value="female"> 3</td>
    <td><input class="radio" type="radio" name="respuesta2" value="female"> 4</td>

    </tr>

如您所见,有两个问题,但我只想在 jquery 数组中获取已检查的收音机以获得正确答案.你能帮我么?

As you can see, there arte two questions but i want only get the checked radios in a jquery array for the correct answers. Can you please help me?

推荐答案

我觉得这可能行得通

$(".radio:checked").each(function() {
console.log($(this).val());
});

相关文章