jquery循环问题

时间:2010-08-30 19:01:07

标签: javascript jquery dom

我在我页面上给定<tr>的每个()循环中。如何循环遍历<th>内的所有$(this),即在当前<tr>内:{/ p>

$('#my_table > tbody > tr').each(function() {
   // how to loop through all the <th>'s inside the current tr?
});

4 个答案:

答案 0 :(得分:1)

$('#my_table > tbody > tr').each(function() {
   $('th', this).each( ... );
});

答案 1 :(得分:1)

你可以在原始循环中执行此操作:

$('#my_table > tbody > tr > th').each(function() {

但是如果由于某些原因你不能这样做,就像循环中有其他代码一样,你可以使用它:

$('th',this).each(function() {

答案 2 :(得分:0)

$(this).find('th').each(...)

OR

$('th', this).each(...)

答案 3 :(得分:-2)

$('#my_table > tbody > tr').each(function() {
  $(this).filter('th').each(function(){
   //your code here
   });
});

但如果您不需要对tr执行任何操作或者可以将它们链接起来,则可以更简洁地完成。

相关问题