如何迭代在jQuery中使用索引的元素? [英] How to iterate the elements using index in jquery?
问题描述
我只有一个只包含class属性的HTML页面。每个班级都有单独的桌子。我只想得到每个表的行数。因为我有n个具有相同类名的表。是否有可能通过使用jquery?
我做了如下操作:
<$ c $ (索引){
document.write(index) ; //它返回页面中的表的数量
});
});
基于该代码,我只需要获取每个表中存在的行数。假设索引返回为3.我可以假设在该页面中有3个表。我只想知道每个表格中有多少行。例如table1:3 rows,table2:2 rows and table3:5 rows like that。
有可能吗?请帮助我实现此目的。
另外,我只想告诉你,我没有任何每个表的id属性。我只想使用class attr not id来实现。
感谢高级用户。
-Sasi
您应该尝试下面的代码
$(document).ready(function(){
var checkStatus = function(elements){
elements.each(function(){
// check it contains the word
if($(this).is(':contains(FAILED)')){
//清空容器然后添加动态容器
$(this).empty( );
$(this).append('< div class =mainStatus> PASSED< / div>');
}
})
};
$(。assertionTable)。each(function(){
checkStatus($(this).find(tr td:last-child));
});
});
I just have an HTML page which contains only class attribute. Each class have individual table. I just wanna get the row count of each table.Since I have n number of table with same class name. Is it possible by using jquery?
I done something as below:
$(document).ready(function(){
$(".testTable").each(function(index){
document.write(index); // It returns number of table in the page
});
});
Based on that code I just need to get the number of rows present in the each table. Just assume that the index returns as 3. I can assume that I have 3 table in that page. And I just wanna know how many rows present in each table. For example table1 :3 rows, and table2 :2 rows and table3 :5 rows as like that.
Is it possible? please help me to achieve this.
Also , I just wanna tell you that I don't have any id attribute for each table. I just want to do it by using only class attr not id.
Thanks in advanced.
-Sasi
You should try below code
$(document).ready(function(){
var checkStatus = function(elements){
elements.each(function(){
//check it contains the word
if($(this).is(':contains("FAILED")')){
//Empty the container and then add dynamic container
$(this).empty();
$(this).append('<div class="mainStatus">PASSED</div>');
}
})
};
$(".assertionTable").each(function(){
checkStatus($(this).find("tr td:last-child"));
});
});
这篇关于如何迭代在jQuery中使用索引的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!