2012-01-13 101 views
0

我是一个jQuery代码,可以得到表td文本的兄弟。 我们如何才能将该文本放入变量?jQuery EACH兄弟姐妹每个变量?

jQuery("tbody tr").each(function() { 
    jQuery("td:not(:first)",this).click(function() { 
     alert(jQuery(this).siblings().text()); 
    }); 
}); 

<table> 
<thead><td>A</td><td>B</td></thead> 
<tbody> 
<tr><td class="aclass">A</td><td class="bclass">B</td></tr> 
</tbody> 
</table> 

Set siblings as variable: 

var txtA = jQuery(this).find(".aclass").text(); 
var txtA = jQuery(this).find(".aclass").text(); 

回答

1

你可以在阵列中添加文本:

 

var textsArr = new Array(); 
jQuery("tbody tr").each(function() { 
    jQuery("td:not(:first)",this).click(function() { 
     textsArr.push(jQuery(this).siblings().text()); 
    }); 
}); 

 
+0

当我提醒警报(textsArr); 它仍然是它只是把它放在数组中,但只有一个数组 数组(“一个数组”); 它应该是数组(“一”,“数组”); – kedomonzter 2012-01-13 08:48:02