jQuery每个变量的每个同级?
我有一个jquery代码,它可以获取表td text的同级。 我们如何将文本放入变量中jQuery每个变量的每个同级?,jquery,Jquery,我有一个jquery代码,它可以获取表td text的同级。 我们如何将文本放入变量中 jQuery("tbody tr").each(function() { jQuery("td:not(:first)",this).click(function() { alert(jQuery(this).siblings().text()); }); }); <table> <thead><td>A</td><td&
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();
jQuery(“tbody tr”)。每个(函数(){
jQuery(“td:not(:first)”,this)。单击(function(){
警报(jQuery(this.this().text());
});
});
AB
AB
将同级设置为变量:
var txtA=jQuery(this.find(“.aclass”).text();
var txtA=jQuery(this.find(“.aclass”).text();
您可以在数组中添加文本:
var textsArr = new Array();
jQuery("tbody tr").each(function() {
jQuery("td:not(:first)",this).click(function() {
textsArr.push(jQuery(this).siblings().text());
});
});
当我发出警报时(textsArr);它仍然是一样的,只是把它放在数组中,但只有一个数组(“一个数组”);它应该是数组(“一”、“数组”);