1. 程式人生 > >jquery獲取表格中所有的checkbox並遍歷

jquery獲取表格中所有的checkbox並遍歷

<table class="table">

<tr>

<td><input type="checkbox" checked=“”checked“”></td>

<td>測試</td>

</tr>

</table>

使得已勾選上的行去掉勾選:

$(".table input[type=checkbox]").attr("checked",false);

$(".table input:checkbox").attr("checked",false);
迴圈遍歷獲取選中行所在的行數及其下一個兄弟節點的值:
$("table input:checkbox").each(function(){
    if($(this).attr("checked")==true){
        alert($("table input:checkbox").index(this))
//值
console.log($(this).parent().parent().children().eq(1).text());
    }
})