使用Each()函数:
$(".CCC").each(function(i){
alert(this.id + " is the " + i + "th div with this class");
});
Run Code Online (Sandbox Code Playgroud)
编辑:
按照要求:
function LoopTroughDivs(selector){
$(selector).each(function(i){
alert(this.id + " is the " + i + "th div with this class");
});
}
Run Code Online (Sandbox Code Playgroud)