0

我有一张像这样的 td 表:

<td age="123">0</td>

使用 jQuery,下面的 JavaScript

$('td[age]').each(function(){
    console.log($('this').attr('age'));
});

将“未定义”打印到 Chrome 中的控制台。

为什么不打印“123”?

4

2 回答 2

4

你在哪里

$('this')

你应该有

$(this)
于 2012-08-20T02:09:45.110 回答
2

工作演示 http://jsfiddle.net/SZSr5​​/

$('td[age]').each(function(){
    alert($(this).html());
});​
于 2012-08-20T02:13:28.773 回答