0
我想在選擇列表的值改變時使用類sel來獲取選擇列表的索引。頁面中有很多。Jquery - 在頁面內查找選擇列表的索引
<p>
<select class="sel">
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
=> return 0 when changed
</p>
<p>
<select class="sel">
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
=> return 1 when changed
</p>
<p>
<select class="sel">
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
=> return 2 when changed
</p>
<p>
<select class="sel">
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
=> return 3 when changed
</p>
<p id="result"></p>
$(function()
{
$('.sel').change(function()
{
console.log($(this).index()) //always returns 0
});
});