简体   繁体   English

如何根据索引取消选中复选框

[英]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.

相关问题 如何根据 localStorage state 选中/取消选中复选框 - How to check/uncheck checkbox based on localStorage state 我们如何根据索引或通过 react-native flatlist 中的键检查/取消选中 flatlist 中的单个复选框 - How can we Check/Uncheck individual checkbox in flatlist based on index or by key in react-native flatlist 如何取消选中AJAX中的复选框? - How to uncheck the checkbox in AJAX? 如何使用 jquery 取消选中复选框 - how to uncheck a checkbox with jquery 如何基于取消选中或选中复选框来禁用/启用Rechatcha - How disable / Enable rechatcha based on uncheck or check from checkbox 基于 v-on:click,如何取消选中 Vuejs 中的复选框值? - Based on v-on:click, How to uncheck the checkbox values in Vuejs? 根据另一个复选框选中/取消选中复选框 - check/uncheck checkbox based on another checkbox 如何使用全选/取消全选在基于分页的表中实现多个复选框,然后将所有选定的复选框 IDS 存储到 localstoarge - How to implement Multiple Checkbox in a pagination based table with Check/Uncheck All and then store all selected checkbox IDS into localstoarge 如何取消选中纯 JavaScript 中的复选框? - How to uncheck a checkbox in pure JavaScript? 如何选中/取消选中键盘上的复选框 - how to check/uncheck a checkbox on keyup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM