jQuery JQuery取消选中div中的所有复选框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4959703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:17:21  来源:igfitidea点击:

JQuery to uncheck all checkboxes within div

jqueryhtml

提问by slandau

<div id="termSheetPopup">
    <div style="text-align:center;">
        <select id="termSheetType">
            <option>Internal</option>
            <option>Borrower Facing</option>
        </select>
    </div>

    <input type="checkbox" name="SummaryInformation">Summary Information<br />
    <input type="checkbox" name="ProductLegs">Product Legs<br />
    <input type="checkbox" name="AmortizationOptions">Amortization Options<br />
    <input type="checkbox" name="Values">Values<br />
    <input type="checkbox" name="Rates">Rates<br />
    <input type="checkbox" name="RatesSpecific">Rates (All-In-Rate, PV01)<br />
    <input type="checkbox" name="AmortizationSchedule">Amortization Schedule<br />
    <input type="checkbox" name="SponsorInfo">Sponsor/Affiliate Info<br />
    <input type="checkbox" name="BorrowerInfo">Borrower Info<br />
    <input type="checkbox" name="SponsorContacts">Sponsor/Affiliate Contacts<br />
    <input type="checkbox" name="CashFlows">Cash Flows<br />
    <input type="checkbox" name="PrePayment">Pre-Payment<br />
    <input type="checkbox" name="FutureExposure">Potential Future Exposure<br />
    <input type="checkbox" name="FutureExposureSpecific">Potential Future Exposure (Max Number and Date Only)<br />
    <input type="checkbox" name="History">History<br />
</div>

What's the JQuery to delete all those checkboxes just underneath that div?

删除该 div 下方所有复选框的 JQuery 是什么?

回答by Silver Light

To uncheck all the checkboxes (as the title asks):

要取消选中所有复选框(如标题所示):

$('#termSheetPopup').find('input[type=checkbox]:checked').removeAttr('checked');

To delete all the checkboxes (as the question asks):

要删除所有复选框(如问题所问):

$('#termSheetPopup').find('input[type=checkbox]:checked').remove();

回答by Pradeep

Another approach would be:

另一种方法是:

Assign a class(just to use as a selector) to each checkbox,

为每个复选框分配一个类(仅用作选择器),

<div id="termSheetPopup">
<div style="text-align:center;">
    <select id="termSheetType">
        <option>Internal</option>
        <option>Borrower Facing</option>
    </select>
</div>

<input type="checkbox" class="chk" name="SummaryInformation">Summary Information<br />
<input type="checkbox" class="chk" name="ProductLegs">Product Legs<br />
<input type="checkbox" class="chk" name="AmortizationOptions">Amortization Options<br />
<input type="checkbox" class="chk" name="Values">Values<br />
<input type="checkbox" class="chk" name="Rates">Rates<br />
<input type="checkbox" class="chk" name="RatesSpecific">Rates (All-In-Rate, PV01)<br />
<input type="checkbox" class="chk" name="AmortizationSchedule">Amortization Schedule<br />
<input type="checkbox" class="chk" name="SponsorInfo">Sponsor/Affiliate Info<br />
<input type="checkbox" class="chk" name="BorrowerInfo">Borrower Info<br />
<input type="checkbox" class="chk" name="SponsorContacts">Sponsor/Affiliate Contacts<br />
<input type="checkbox" class="chk" name="CashFlows">Cash Flows<br />
<input type="checkbox" class="chk" name="PrePayment">Pre-Payment<br />
<input type="checkbox" class="chk" name="FutureExposure">Potential Future Exposure<br />
<input type="checkbox" class="chk" name="FutureExposureSpecific">Potential Future Exposure (Max Number and Date Only)<br />
<input type="checkbox" class="chk" name="History">History<br />

And use below line to check all checkboxes:

并使用以下行检查所有复选框:

$('.chk').attr("checked", true);

For deleting, I guess you want to delete checkbox along with the title. Insert them into a div with some id. And remove that div:

对于删除,我猜您想连同标题一起删除复选框。将它们插入一个带有一些 id 的 div 中。并删除该 div:

 <div id="someid"><input type="checkbox" class="chk" name="SummaryInformation">Summary Information</div> 

Use below code to delete:

使用以下代码删除:

$('#someid').remove()

This will remove checkbox as wel as the text since the div is removed.

由于删除了 div,这将删除复选框以及文本。