jQuery 循环遍历表中的所有 td 元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5193973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
loop through all td elements in a table
提问by user517406
How would I loop through all the td elements in a table? I need to find the id of each td and compare it against a value. Any help would really be appreciated!
如何遍历表中的所有 td 元素?我需要找到每个 td 的 id 并将其与一个值进行比较。任何帮助将不胜感激!
回答by alexn
Use jQuery.eachto loop all your td's:
使用jQuery.each来循环你所有的 td:
$("td").each(function() {
var id = $(this).attr("id");
// compare id to what you want
});
回答by wong2
var all_td_in_a_table = $("#table-id td")
,
var all_td_in_a_table = $("#table-id td")
,
then you can do a loop
然后你可以做一个循环
回答by TanvirChowdhury
$('#tableId').find('tr').each(function () {
$(this).find("td[id^='tdId']").each(function (i, item) {
//do your task here
});
});
Or the effective one is get all the tds from table first
或者有效的方法是先从表中获取所有 tds
var totalTdsInTable = $("#table-id td");
Now loop through totalTdsInTable
现在循环遍历 totalTdsInTable