我有3个具有相同类名的表table-sort.我想访问那些表.each()并计算tr内部tbody.
是$("this tbody tr").length吗?
$('.table-sort').each(function(index) {
var rowCount = $("this tbody tr").length; //not work , Could you please correct this?
var rowCount1 = $(this).find('tbody > tr').length; //this is working fine
alert(rowCount + '-' + rowCount1);
})
Run Code Online (Sandbox Code Playgroud)
Gab*_*oli 12
这是代码
$('.table-sort').each(function(index) {
var rowCount = $("tbody tr", this).length; //will work now..
var rowCount1 = $(this).find('tbody > tr').length; //this is working fine
alert(rowCount + '-' + rowCount1);
})
Run Code Online (Sandbox Code Playgroud)
但是,你使用第二个代码,它的工作原理,应该是足够..
$('.table-sort').each(function(index) {
var rowCount = this.rows.length;
})
Run Code Online (Sandbox Code Playgroud)