Php 在jquery中循环使用特定类的同级
我有Php 在jquery中循环使用特定类的同级,php,jquery,zend-framework,Php,Jquery,Zend Framework,我有tr类firstrow和tr类addrows。addrows类总是在firstrow类之后,我想计算每个firstrow tr之后addrow tr的数量。在我的例子中,它应该是1和6。这是我的密码 <table id="sdx-O_BAR_added" class="roomtypeadded"> <tbody> <tr class="header"> </tr> <tr class="header"> </tr> &
tr
类firstrow和tr
类addrows。addrows类总是在firstrow类之后,我想计算每个firstrow tr之后addrow tr的数量。在我的例子中,它应该是1和6。这是我的密码
<table id="sdx-O_BAR_added" class="roomtypeadded">
<tbody>
<tr class="header">
</tr>
<tr class="header">
</tr>
<tr class="firstrow">
</tr>
<tr class="addrows">
</tr>
<tr class="header">
</tr>
<tr class="header">
</tr>
<tr class="firstrow">
</tr>
<tr class="addrows">
</tr>
<tr class="addrows">
</tr>
<tr class="addrows">
</tr>
<tr class="addrows">
</tr>
<tr class="addrows">
</tr>
<tr class="addrows">
</tr>
</tbody>
</table>
我不知道如何做到这一点,我尝试使用jquerysibbines()
和next()
。但是我做不到,请帮忙(Try$(“第一行”)。每个()
在该函数中,尝试执行$(this).next()您可以尝试
$.nextAll()
函数:
$('table tr.firstrow').nextAll('tr.addrows').length;
这将为您提供tr.firstrow
元素后面的所有行的总数
如果希望获得每个tr.firstrow
的.addrows类元素的数组,您可能会发现jQuery的$.map()
函数更有用:
var counts = $('table tr.firstrow').map(function(){
return $(this).nextUntil(':not(.addrows)').length;
});
这将返回一个数字数组-实际上是小计(例如[1,6])。这应该可以
$("tr.firstrow").siblings("tr.addrows")
这只是您想要的实际数字,还是您想要返回匹配的元素集?是的。我需要重新返回匹配的元素。谢谢。我想这将返回所有包含类addrows的行,抱歉,这不是我想要的