3

在 HTML 中,您可以分配标签标签的“for”属性,以便当用户单击标签时,它会选择相应的单选按钮:

<input type="radio" name="group" value="1" id="radioButtonId" />
<label for="radioButtonId">label text</label>

使用 javascript(特别是使用 Prototype JS 框架)动态创建标签标签时存在问题。Forfor 循环的保留关键字。Prototype JS 的文档显示className是保留关键字class的代码字,但没有说明 for 的代码字什么。它是什么?

new Element(
 'label', {
  for: 'radioButtonId'
 }
).update('label text');
4

3 回答 3

9

className是属性对应的标准 DOMclass属性;它与原型本身无关。

同理,属性对应的 DOMfor属性是htmlFor.

于 2010-12-29T21:08:00.560 回答
5

要将保留的工作用作对象文字中的键,只需将其用引号括起来,如下所示:

new Element(
 'label', {
  'for': 'radioButtonId'
 }
).update('label text');
于 2010-12-29T20:59:31.670 回答
1

你试过用引号括起来吗?

new Element('label',{'for':'radioButtonId'}).update('label text');
于 2010-12-29T21:02:09.280 回答