[英]Iterate Through an HTML Array With a Dropdown Box
I have an arrary of values in an html page: eg 我在html页面中有很多值:例如
<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? $('input ...')。each(function)是否应该与上面的第一个代码段(即billingCity)相同?
Use this instead: 使用此代替:
$('select[id="ibillingState[]"] option').each(function() {
$billingCity = $(this);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.