我試圖訪問foreach循環的索引來訪問的第二個元素如何獲得第一循環的指數爲另一個陣列的jQuery
$.each("input:checkbox[name=city[]]:checked", function (index, item) {
var category = $('select[name="category[]["' + index + '"]"]').val();
alert(category);
var split = category = category.split('_');
var category = split[0];
if (category == "0") {
alert('Please select hotel category');
validate = "false";
return false;
}
else {
validate = "true";
}
});
這是我的HTML
<select name="category[]"
id="webmenus_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>"
onchange="showValue(this.value)"
>
<option value="0" selected="selected" title="Please select hotel category"></option>
<option value="5_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/5star.png"></option>
<option value="4_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/4star.png"></option>
<option value="3_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/3star.png"></option>
<option value="2_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/2star.png"></option>
<option value="1_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/1star.png"></option>
</select>
但我越來越沒有定義。
感謝,
您能得到什麼爲未定義?索引或類別? –