0

HTML:

<label name="table_id" for="1280461">Rock</label>
<label name="table_id" for="1291065">Paper</label>

这不起作用:

$$('label[name="table_id"]').each(function(s){ 
  console.log(s.for); 
});
4

3 回答 3

1
s.readAttribute('for');

参见: http: //prototypejs.org/api/element/readattribute

于 2012-05-15T19:29:56.737 回答
1

for是 Javascript 中的关键字。您不能以“ s.for”形式使用它。

使用DOM ElementgetAttribute函数:

$$('label[name="table_id"]').each(function(s){ 
    console.log(s.getAttribute('for')); 
});
于 2012-05-15T19:40:49.493 回答
0

我创造了一个小提琴来回答这个问题。希望这对你有意义。

http://jsfiddle.net/QmEWD/

于 2012-05-15T19:43:14.597 回答