我有几个 class='CCC' 的 Div。我想使用 jQuery 将所有这些 div 放入一个数组中,然后循环遍历该数组。如何做到这一点。
最佳答案
使用 Each() 函数:
$(".CCC").each(function(i){
alert(this.id + " is the " + i + "th div with this class");
});
编辑:
根据要求:
function LoopTroughDivs(selector){
$(selector).each(function(i){
alert(this.id + " is the " + i + "th div with this class");
});
}
关于jQuery 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/829112/