2015-01-08 2 views
0

나는 모든 tr보다는 오히려 확인한 것을 얻고 있습니다. 이확인 된 모든 행을 찾으십시오.

시도 반환하는 대신 값을 설정합니다 prop('checked')prop('checked', true) 때문에

$.each($("#sample-table-1 tr.main"), function (key, value) { 
    if ($(value).closest("td").find('[type=checkbox]').prop('checked', true)) 
     console.log($(value).attr('id')); 
}); 

답변

3

할 수 있습니다 오히려 확인 확인란을 얻고 그들의 가장 가까운 부모 TR을 얻을 :

$("#sample-table-1 tr.main :checked").each(function(){ 
    console.log($(this).closest('tr').attr('id')); 
}); 

행에 여러 체크 박스 :

$("#sample-table-1 tr.main").filter(function(){ 
    return $(this).find(':checked').length > 0; 
}).each(function(){ 
    console.log($(this).attr('id')); 
}); 
+0

그래,이 일했는데 행에 다른 확인란이있는 경우를 대비해서 뭔가 넣어야합니다. – Mert

+0

필터 방법으로 업데이트 된 답변을 확인하십시오. –

+0

나는 이것을 이렇게 풀었다. n 개의 체크 박스가 체크 되어도 $ ("# sample-table-1 tr.main td.check : checked") – Mert

0

변화 prop('checked', true)

$.each($("#sample-table-1 tr.main"), function (key, value) { 
    if ($(value).find('[type=checkbox]').prop('checked')) 
     console.log($(value).attr('id')); 
}); 
+0

신속하게 반환 아무것도 시도하지. – Mert

0

이 일을 시도해보십시오

$.each($("#sample-table-1 tr.main"), function (key, value) { 
    console.log($(value)); //this is for debugging purpose only. What does it write in console? 
    if ($(value).closest("td").find('[type=checkbox]').prop('checked')===true) 
     console.log($(value).attr('id')); 
}); 
관련 문제