내 코드 here의 기본 데모를 만들었습니다.상위 요소의 확인란을 선택하십시오.
원하는 기능 :
내가 그 TR 내부 TR 체크 박스를 클릭
체크 얻을해야하고 그럴 강조 받아야합니다. 확인란을 클릭 할 때도 마찬가지입니다.문제점 :
위의 기능은 확인란을 클릭하면 완벽하게 작동합니다. 그러나 tr을 클릭하면 첫 번째 클릭에 대해서만 작동합니다. tr을 다시 클릭하면 체크 박스가 다시 체크 인되지 않습니다.
무엇이 문제 일 수 있습니까? 도와주세요.
jquery 및 html은 jsfiddle 링크에서 찾을 수 있습니다. 하지만 여전히 여기에 참조 할 수있다 :
HTML :
<table border="1" width="100%">
<tbody>
<tr>
<th colspan="4">NEW PRODUCTS FOUND</th>
</tr>
<tr>
<th>Shelf</th>
<th>Product</th>
<th>Corrected</th>
</tr>
<tr class="hover_row hover_row_product pr_row_1">
<td>aa</td>
<td>sdcsd</td>
<td>
<input type="checkbox" class="product_correction" product_id="1">
</td>
</tr>
<tr class="hover_row hover_row_product pr_row_2">
<td>aa</td>
<td>sdcsdc</td>
<td>
<input type="checkbox" class="product_correction" product_id="2">
</td>
</tr>
<tr class="hover_row hover_row_product pr_row_3">
<td>aa</td>
<td>dbfgbdfgb</td>
<td>
<input type="checkbox" class="product_correction" product_id="3">
</td>
</tr>
</tbody>
</table>
JS :
/*Correction proccess*/
$('.hover_row_product').click(function (e) {
var checkbox = $(this).find(':checkbox');
if ($(e.target).closest('input[type="checkbox"]').length > 0) {
//check box clicked
} else {
checkbox.attr('checked', !checkbox.attr('checked'));
}
$prod_id = checkbox.attr('product_id');
$input_checked = 2;
if (checkbox.is(':checked')) {
$input_checked = 1;
$('.pr_row_' + $prod_id).addClass('corrected_row');
} else {
$input_checked = 0;
$('.pr_row_' + $prod_id).removeClass('corrected_row');
}
});