[英]How to uncheck checkbox based on index
How can i uncheck checkbox based on checkbox index. 我如何根据复选框索引取消选中复选框。 I have tried to following script for uncheck checkbox based on index but it's not doing anything.
我试图按照索引取消选中复选框的脚本,但它没有执行任何操作。
$('.change_product_price').each(function(index, element) {
$(".chkIt").eq(index).prop("checked", false); // first method
$('.chkIt:checked').eq(index).prop("checked", false); //second method
});
HTML 的HTML
<tr class="product_row">
<td class="small-check SerialNumber"><input class="chkIt" type="checkbox" name="products[product_id][]" value="76" qty="0" product_weight="0"></td>
<td data-th="Product Name" class="fourth_i1">8 PACK SPECIALIST EMBOSSED SILVER FOIL 500 SHEET BOX 12CM X 20CM</td>
<td data-th="Part Number" class="grid-text">EMBOSS-Pre-Cut x 8 Pack</td>
<td class="small-check MarkGift"><input class="chkItg" type="checkbox" name="gift[product_id][]" value="76"></td>
<td data-th="Quantity" class="grid-text">
<select name="products[quantity][76][]" class="change_product_price">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type="hidden" class="promo_min_quantity" name="promo_min_quantity" value="">
<input type="hidden" class="promo_free_units" name="promo_free_units" value="0">
</td>
<td style="display:none;" class="grid-text"><span class="product_weight">5.8</span></td>
<td data-th="Price / unit" class="grid-text">$<span class="product_price" prevvalue="180.00">180.00</span></td>
<td data-th="Promo code" class="grid-text">N/A<!-- <input type="hidden" value="" name="products[promo_code][76][]" />--></td>
<td data-th="Price" class="grid-text">$<span class="product_total_price">180.00</span></td>
</tr>
<tr class="product_row">
<td class="small-check SerialNumber"><input class="chkIt" type="checkbox" name="products[product_id][]" value="76" qty="0" product_weight="0"></td>
<td data-th="Product Name" class="fourth_i1">12 PACK SPECIALIST EMBOSSED SILVER FOIL 500 SHEET BOX 12CM X 20CM</td>
<td data-th="Part Number" class="grid-text">EMBOSS-Pre-Cut x 8 Pack</td>
<td class="small-check MarkGift"><input class="chkItg" type="checkbox" name="gift[product_id][]" value="78"></td>
<td data-th="Quantity" class="grid-text">
<select name="products[quantity][78][]" class="change_product_price">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type="hidden" class="promo_min_quantity" name="promo_min_quantity" value="">
<input type="hidden" class="promo_free_units" name="promo_free_units" value="0">
</td>
<td style="display:none;" class="grid-text"><span class="product_weight">5.8</span></td>
<td data-th="Price / unit" class="grid-text">$<span class="product_price" prevvalue="180.00">180.00</span></td>
<td data-th="Promo code" class="grid-text">N/A<!-- <input type="hidden" value="" name="products[promo_code][78][]" />--></td>
<td data-th="Price" class="grid-text">$<span class="product_total_price">180.00</span></td>
</tr>
Use for unchecked the checkbox 用于未选中的复选框
$(".chkIt").eq(index).removeAttr('checked');
Use for checked the checkbox 用于选中复选框
$('.chkIt').eq(index).attr('checked','checked');
Please check this one 请检查这个
$(document).on('change', '.change_product_price', function () { $(this).closest('tr.product_row').find('td').each(function () { $(this).find("input.chkIt").prop("checked",false); $(this).find("input.chkItg").prop("checked",false); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <table><tr class="product_row"> <td class="small-check SerialNumber"><input class="chkIt" type="checkbox" name="products[product_id][]" value="76" qty="0" product_weight="0"></td> <td data-th="Product Name" class="fourth_i1">8 PACK SPECIALIST EMBOSSED SILVER FOIL 500 SHEET BOX 12CM X 20CM</td> <td data-th="Part Number" class="grid-text">EMBOSS-Pre-Cut x 8 Pack</td> <td class="small-check MarkGift"><input class="chkItg" type="checkbox" name="gift[product_id][]" value="76"></td> <td data-th="Quantity" class="grid-text"> <select name="products[quantity][76][]" class="change_product_price"> <option>0</option> <option>1</option> <option>2</option> <option>3</option> </select> <input type="hidden" class="promo_min_quantity" name="promo_min_quantity" value=""> <input type="hidden" class="promo_free_units" name="promo_free_units" value="0"> </td> <td style="display:none;" class="grid-text"><span class="product_weight">5.8</span></td> <td data-th="Price / unit" class="grid-text">$<span class="product_price" prevvalue="180.00">180.00</span></td> <td data-th="Promo code" class="grid-text">N/A<!-- <input type="hidden" value="" name="products[promo_code][76][]" />--></td> <td data-th="Price" class="grid-text">$<span class="product_total_price">180.00</span></td> </tr> <tr class="product_row"> <td class="small-check SerialNumber"><input class="chkIt" type="checkbox" name="products[product_id][]" value="76" qty="0" product_weight="0"></td> <td data-th="Product Name" class="fourth_i1">12 PACK SPECIALIST EMBOSSED SILVER FOIL 500 SHEET BOX 12CM X 20CM</td> <td data-th="Part Number" class="grid-text">EMBOSS-Pre-Cut x 8 Pack</td> <td class="small-check MarkGift"><input class="chkItg" type="checkbox" name="gift[product_id][]" value="78"></td> <td data-th="Quantity" class="grid-text"> <select name="products[quantity][78][]" class="change_product_price"> <option>0</option> <option>1</option> <option>2</option> <option>3</option> </select> <input type="hidden" class="promo_min_quantity" name="promo_min_quantity" value=""> <input type="hidden" class="promo_free_units" name="promo_free_units" value="0"> </td> <td style="display:none;" class="grid-text"><span class="product_weight">5.8</span></td> <td data-th="Price / unit" class="grid-text">$<span class="product_price" prevvalue="180.00">180.00</span></td> <td data-th="Promo code" class="grid-text">N/A<!-- <input type="hidden" value="" name="products[promo_code][78][]" />--></td> <td data-th="Price" class="grid-text">$<span class="product_total_price">180.00</span></td> </tr></table>
尝试,
$('.chkIt').eq(index)[0].checked = false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.