我在div中有多个下拉列表。这是自动生成的。我做过那项工作。但我需要获得第n次下拉。请帮我搞定。
$('#show_label_categories')[1].find('select').each(function () {
});
<div id="show_label_categories">
<select name="search_category" class="form-control parent">
<option value="-1" selected="selected">-- Select --</option>
<option value="1">Tutorials</option>
<option value="2">Demos</option>
<option value="3">Entertainment</option>
<option value="4">Real Estate</option>
<option value="5">Web Development</option>
<option value="6">Browsers</option>
<option value="43">Laptop</option>
<option value="46">1</option>
</select>
<select name="search_category" class="form-control parent">
<option value="-1" selected="selected">-- Select --</option>
<option value="12">PHP demos</option>
<option value="13">jQuery demos</option>
</select>
<select name="search_category" class="form-control parent">
<option value="-1" selected="selected">-- Select --</option>
<option value="36">Good Demos</option>
</select>
</div>
答案 0 :(得分:1)
您可以使用:eq(n)
选择器,因此对于第二个select
:
$('select:eq(1)');
n
是从零开始的索引。
将其涂成红色的示例:
$('#show_label_categories select:eq(1)').css('color', 'red');
alert('Length: ' + $('#show_label_categories select:eq(1)').length);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="show_label_categories">
<select name="search_category" class="form-control parent">
<option value="-1" selected="selected">-- Select --</option>
<option value="1">Tutorials</option>
<option value="2">Demos</option>
<option value="3">Entertainment</option>
<option value="4">Real Estate</option>
<option value="5">Web Development</option>
<option value="6">Browsers</option>
<option value="43">Laptop</option>
<option value="46">1</option>
</select>
<select name="search_category" class="form-control parent">
<option value="-1" selected="selected">-- Select --</option>
<option value="12">PHP demos</option>
<option value="13">jQuery demos</option>
</select>
<select name="search_category" class="form-control parent">
<option value="-1" selected="selected">-- Select --</option>
<option value="36">Good Demos</option>
</select>
</div>
&#13;
答案 1 :(得分:0)
你可以使用
$("#show_label_categories").children("select:nth(1)");