jQuery 循环

标签 jquery

我有几个 class='CCC' 的 Div。我想使用 jQuery 将所有这些 div 放入一个数组中,然后循环遍历该数组。如何做到这一点。

最佳答案

使用 Each() 函数:

$(".CCC").each(function(i){
   alert(this.id + " is the " + i + "th div with this class");
 });

http://docs.jquery.com/Each

编辑:

根据要求:

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/

相关文章:

javascript - 手动或以编程方式单击时与 Prop ('checked' 不一致)

javascript - 为什么这个 Highcharts 图表只显示第一个和最后一个节点的工具提示?

javascript 获取带有样式的元素

javascript - 如何在 onchange 事件期间访问选择框中的数据值

javascript - 无法使用 AJAX localhost 请求 html 内容

javascript - $.post 总是返回从 mvc 发起的 View

javascript - jQuery next 方法替代

javascript - 首次加载后从导航中删除类

javascript - 外部 HTML 检索

jquery - 滚动时如何更改导航栏内容?