Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为每个子级循环jQuery_Javascript_Jquery_Loops - Fatal编程技术网

Javascript 为每个子级循环jQuery

Javascript 为每个子级循环jQuery,javascript,jquery,loops,Javascript,Jquery,Loops,如何编写用于(i=1;…);函数,它允许我循环遍历每个子类并添加不同的类 $('#WebPartWPQ3 > table:first-child').addClass('blogpost1'); $('#WebPartWPQ3 > table:nth-child(2)').addClass('blogpost2'); $('#WebPartWPQ3 > table:nth-child(3)').addClass('blogpost3'); $('#WebPartWPQ3 >

如何编写用于(i=1;…);函数,它允许我循环遍历每个子类并添加不同的类

$('#WebPartWPQ3 > table:first-child').addClass('blogpost1');
$('#WebPartWPQ3 > table:nth-child(2)').addClass('blogpost2');
$('#WebPartWPQ3 > table:nth-child(3)').addClass('blogpost3');
$('#WebPartWPQ3 > table:nth-child(4)').addClass('blogpost4');
$('#WebPartWPQ3 > table:nth-child(5)').addClass('blogpost5');
$('#WebPartWPQ3 > table:nth-child(6)').addClass('blogpost6');
$('#WebPartWPQ3 > table:nth-child(7)').addClass('blogpost7');
$('#WebPartWPQ3 > table:nth-child(8)').addClass('blogpost8');
$('#WebPartWPQ3 > table:nth-child(9)').addClass('blogpost9');
试一试

如果
#WebPartWPQ3
具有非表的子节点,该怎么办?最好在
$(“#WebPartWPQ3”).children()上循环并检查它们是否是表。
$('#WebPartWPQ3 > table').each(function(i,j){

 $(this).addClass("blogpost"+(i+1));
});