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);
});
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);
});
s.readAttribute('for');
for
是 Javascript 中的关键字。您不能以“ s.for
”形式使用它。
使用DOM Element
的getAttribute函数:
$$('label[name="table_id"]').each(function(s){
console.log(s.getAttribute('for'));
});
我创造了一个小提琴来回答这个问题。希望这对你有意义。