如何计算每行中的选择标记

时间:2022-03-09 09:08:44

I want to count the select tag in each row. I used:

我想计算每一行中的select标签。我用了:

alert($('#table tr select').length);

sql fiddle:http://jsfiddle.net/xs8zfter/ When I execute this I got 6. But actually I need 3(ie, each row have 3 I

sql小提琴:http://jsfiddle.net/xs8zfter/当我执行这个我得到6.但实际上我需要3(即每行有3个我

2 个解决方案

#1


For that, You need to iterate over tr elements and then find number of select elements in each pf them. Like this:

为此,您需要迭代tr元素,然后在每个元素中查找选择元素的数量。像这样:

$('#table tr').each(function(){
  alert($(this).find('select').length)
});

Working Demo

#2


Then target each row:

然后定位每一行:

$('#table tr').each(function() {
   alert($(this).find('select').length);
});

This will alert the number 3 twice, because there are 2 rows that have 3 select elements each

这将两次警告数字3,因为有2行每个都有3个选择元素

Here is the DEMO

这是DEMO

#1


For that, You need to iterate over tr elements and then find number of select elements in each pf them. Like this:

为此,您需要迭代tr元素,然后在每个元素中查找选择元素的数量。像这样:

$('#table tr').each(function(){
  alert($(this).find('select').length)
});

Working Demo

#2


Then target each row:

然后定位每一行:

$('#table tr').each(function() {
   alert($(this).find('select').length);
});

This will alert the number 3 twice, because there are 2 rows that have 3 select elements each

这将两次警告数字3,因为有2行每个都有3个选择元素

Here is the DEMO

这是DEMO