2011-02-10 11 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> 

Co to jest JQuery, aby usunąć wszystkie te pola wyboru znajdujące się pod tym działaniem?JQuery, aby odznaczyć wszystkie pola wyboru w obszarze div

+0

Czy chcesz je usunąć, czy odznaczyć? – Loktar

+0

Moja zła literówka. Tytuł jest poprawny – slandau

Odpowiedz

50

Aby usunąć zaznaczenie wszystkich pól wyboru (jak prosi tytuł):

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

Aby usunąć wszystkie pola wyboru (jak pytanie dotyczy):

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

tylko zastanawiasz się ... czy '.each()' nie jest tutaj potrzebny? –

+1

'$ ('# termSheetPopup input: checked'). RemoveAttr ('checked');' zrobiłby to też i będzie nieco bardziej zwięzły. Jedyne wejście, które może mieć: zaznaczone jako atrybut, to mimo wszystko pole wyboru. " –

+1

@Scott Brown Przycisk radiowy również może być sprawdzony –

2

Innym rozwiązaniem byłoby:

Przypisz klasę (tylko jako selektor) do każdego pola wyboru,

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

I używać poniżej linii, aby sprawdzić wszystkie pola:

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

Do usuwania, chyba, że ​​chcesz usunąć pole wyboru wraz z tytułem. Wstaw je do div z jakimś id. I usunąć ten div:

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

skorzystać z poniższego kodu, aby usunąć:

$('#someid').remove() 

To usunie wyboru jak wel jako tekst, ponieważ div jest usuwany.

Powiązane problemy