给定一个包含许多div子元素的div,并且运行时派生号码为ChildrenPerRow
,如何在每个“虚拟”行中选择不是该虚拟行上最后一个元素的所有子项?根据nth,mth,oth,...,pattern来选择孩子吗?
例如,如果ChildrenPerRow = 5
,选择应该返回1,第2,第3,第4,第6,第7,第8,第9,第11,第12,第13,第14等,如果ChildrenPerRow = 4
,选择应该返回1号
var FilterStr = '';
for(var i=1; i<ChildrenPerRow;i++){
FilterStr+=':nth-child('+i+'n),';
}
FilterStr = FilterStr.replace(/(^,)|(,$)/g, "");
$Children.filter(FilterStr).doSomething();
,类似的会产生一个选择:,第2,第3,第5,第6,第7,第9,第10,第11,第13,第14,第15等
我已经使用类似尝试
:nth-child(1n),:nth-child(2n),:nth-child(3n),:nth-child(4n)
B这选择每个孩子。我也觉得使用一下来构建选择器字符串效率不高。我认为这可以使用不选择器来完成,但我想知道如何使用正选择器来完成。
所以问题是,什么是有效的方式来实现这一点?
我想是这样,让我检查我什么时候回来。 – Nick 2014-11-21 22:04:26