2012-01-13 100 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