简体   繁体   中英

Iterate Through an HTML Array With a Dropdown Box

I have an arrary of values in an html page: eg

    <td><input type="text"  id="ibillingCity[]" name="idbillingCity" value="Springfield"></input></td>

later on in the script tag I iterate through all the values using:

    $('input[id="ibillingCity[]"]').each(function() {
    $billingCity = $(this); 

This works as expected and no issues with this

However when I try the same with a dropdown (select), it does not iterate through the values like a simple text field (ie like above)

    <select  id="ibillingState[]"   name="idbillingState"   class="compcol11">
      <option value="AB" >Alberta</option>
      <option value="BC" >Brittish Columbia</option>
    </select>

Shouldn't the $('input...').each(function) work the same as the first snippet (ie billingCity) as above?

Use this instead:

$('select[id="ibillingState[]"] option').each(function() {
    $billingCity = $(this); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM