我需要循环遍历所有表格元素,在某处保持索引,然后循环遍历那些表格内的所有元素。我的想法是将表格内元素的信息与它们所在表格的索引一起添加到数据库中。
$('table').each(function(index) { $(this).find('*').each(function() { /* do magic */ }); });
$('table').children().hide();
.children()
find()
.children()
只会遍历一层。而find()
则是递归的。 - Jimbo