<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 />
我需要在 JQuery 中循环遍历所有这些,并创建一个包含所检查名称的数组。我该怎么做?
最佳答案
var names = [];
$("checkbox:checked").each(function(){
names.push($(this).attr("name"));
})
您可能需要在要执行此操作的复选框周围添加一个 div,这样就不会循环遍历屏幕上的所有复选框。
如果您这样做,选择器将更改为:
$("#mydiv checkbox:checked")
其中 mydiv
是该 div 的 id
关于jquery - 循环遍历复选框并收集已选中复选框的名称 - JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4962698/