【问题标题】:JQuery to uncheck all checkboxes within divJQuery取消选中div中的所有复选框
【发布时间】:2012-03-30 03:42:41
【问题描述】:
<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>

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

【问题讨论】:

  • 您希望它们被删除还是取消选中?
  • 我的错字。标题正确

标签: jquery html


【解决方案1】:

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

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

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

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

【讨论】:

  • $('#termSheetPopup input:checked').removeAttr('checked'); 也会这样做,而且会更简洁一些。无论如何,唯一可以将 :checked 作为属性的输入是复选框。`
  • @Scott Brown 单选按钮也可以勾选
【解决方案2】:

另一种方法是:

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

<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 />

并使用下面的行来检查所有复选框:

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

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

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

使用以下代码删除:

$('#someid').remove()

这将删除复选框以及文本,因为 div 已删除。

【讨论】:

    猜你喜欢
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 2017-04-22
    • 2012-02-02
    • 2014-05-23
    • 1970-01-01
    相关资源
    最近更新 更多