2011-02-10 31 views
13
<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> 

JQuery để xóa tất cả các hộp kiểm đó ngay bên dưới div đó là gì?JQuery để bỏ chọn tất cả các hộp kiểm trong div

+0

Bạn có muốn xóa hoặc bỏ chọn chúng không? – Loktar

+0

Lỗi đánh máy xấu của tôi. Tiêu đề là chính xác – slandau

Trả lời

50

Để bỏ chọn tất cả các hộp kiểm (như tiêu đề yêu cầu):

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

Để xóa tất cả các hộp kiểm (như các câu hỏi yêu cầu):

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

chỉ cần tự hỏi ... là '.each()' không cần thiết ở đây? –

+1

'$ ('# termSheetPopup input: checked'). RemoveAttr ('checked');' sẽ làm điều đó quá và ngắn gọn hơn một chút. Đầu vào duy nhất có thể có: được chọn làm thuộc tính là hộp kiểm anyway.' –

+1

@Scott Brown nút radio cũng có thể được kiểm tra –

2

cách tiếp cận khác sẽ là:

Chỉ định một lớp (chỉ để sử dụng làm công cụ chọn) cho mỗi hộp kiểm,

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

Và sử dụng dưới đường để kiểm tra tất cả các hộp kiểm sau:

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

Đối xóa, tôi đoán bạn muốn xóa hộp kiểm cùng với tiêu đề. Chèn chúng vào một div với một số id. Và loại bỏ div rằng:

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

Sử dụng mã dưới đây để xóa:

$('#someid').remove() 

này sẽ loại bỏ hộp kiểm như wel như các văn bản kể từ khi div được lấy ra.

Các vấn đề liên quan