0

我想选择“play”类的所有元素并将它们添加到数组“esArreglo”中。

.html 文件:

<td id="b1" class></td>
<td id="b2" class></td>
<td id="b3" class="play"></td>
<td id="b4" class="play"></td>

代码:

$('td.play').each(function() {
    notas.push(this.id)};

var esArreglo = notas.join(',');

我怎样才能解决这个问题?谢谢。

4

2 回答 2

1

你可以使用jQuery.map

var esArreglo = $('td.play').map(function() {
  return this.id;
}).get().join(',');
于 2012-08-17T15:03:30.837 回答
0

可能因为你错过);.each

$('td.play').each(function() {
    notas.push(this.id)
});

var esArreglo = notas.join(',');
于 2012-08-17T15:03:13.367 回答