我的 html 有多个具有相同类的下拉框。我从每个输入框中获取一个值,然后将其<select>
作为选择器传递给。我从输入框中得到的值是正确的,但是我在选择下拉框时遇到了麻烦。
HTML:
<div id="orange">
<input type="text" class="hide" value="AM" />
<select class="ampm">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
<br>
<input type="text" class="hide" value="AM" />
<select class="ampm">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
<br>
<input type="text" class="hide" value="PM" />
<select class="ampm">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
</div>
<div id="apple">
<input type="text" class="hide" value="AM" />
<select class="ampm">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
<br>
<input type="text" class="hide" value="PM" />
<select class="ampm">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
</div>
JS:
$(function () {
$('div').each(function(){
$(this).find('.hide').each(function () { //inputbox
$(this).find('.ampm').val($(this).val()); //option
alert($(this).val());
});
});
});