我有一张像这样的 td 表:
<td age="123">0</td>
使用 jQuery,下面的 JavaScript
$('td[age]').each(function(){
console.log($('this').attr('age'));
});
将“未定义”打印到 Chrome 中的控制台。
为什么不打印“123”?
我有一张像这样的 td 表:
<td age="123">0</td>
使用 jQuery,下面的 JavaScript
$('td[age]').each(function(){
console.log($('this').attr('age'));
});
将“未定义”打印到 Chrome 中的控制台。
为什么不打印“123”?
你在哪里
$('this')
你应该有
$(this)
工作演示 http://jsfiddle.net/SZSr5/
$('td[age]').each(function(){
alert($(this).html());
});