将每个已检查的单选按钮值从HTML表存储到Jquery中的数组

时间:2014-04-22 15:26:31

标签: javascript jquery html

我在HTML标记中有以下代码

<table>
    <tr>
        <td>
            <input type="radio" name="s1" value="1" checked/>
            <input type="radio" name="s1" value="0"/>
        </td>
    </tr>
    <tr>
        <td>
            <input type="radio" name="s2" value="1"/>
            <input type="radio" name="s2" value="0" checked/>
        </td>
    </tr>
</table>

如何使用JQuery / Javascript从表中的每一行获取每个选中的值并将其存储到数组中。

例如:在上述情况下,我应该 1,0

1 个答案:

答案 0 :(得分:1)

使用这种方式

var array = []; 
$('input:checked').each(function(){
    array.push($(this).val());
});