jQuery .each()索引?
问题描述:
我正在使用
$('#list option').each(function(){
//do stuff
});
循环遍历列表中的选项。
我想知道如何获得当前循环的索引?
to loop over the options in a list. I am wondering how I could get the index of the current loop?
因为我不想让var i = 0;
和循环内部有i ++;
as I dont want to have to have var i = 0; and inside the loop have i++;
答
$('#list option').each(function(index){
//do stuff
alert(index);
});
提醒索引:)