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 に答える