2组具有相同ID的单选按钮
2 sets of radio buttons with same IDs
是否可以有 2 组单选按钮共享一个 ID?我似乎无法让他们彼此友好相处。
演示:http://abenjamin765.github.io/slidemenu/
<input type="radio" name="set-one" id="radio-one">
<input type="radio" name="set-one" id="radio-two">
<input type="radio" name="set-one" id="radio-three">
<input type="radio" name="set-two" id="radio-one">
<input type="radio" name="set-two" id="radio-two">
<input type="radio" name="set-two" id="radio-three">
干杯!
没有。 ID 属性 必须 是唯一的。 ID 属性表示该单个元素的唯一标识。
来自HTML5 specification's id
attribute section:
3.2.5.1 The id attribute
The id
attribute specifies its element's unique identifier (ID).
The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character.
如果您想让它们共享一个引用(例如,出于样式目的),您可以改为使用 class
属性:
<input type="radio" name="set-one" class="radio-one">
<input type="radio" name="set-one" class="radio-two">
<input type="radio" name="set-one" class="radio-three">
<input type="radio" name="set-two" class="radio-one">
<input type="radio" name="set-two" class="radio-two">
<input type="radio" name="set-two" class="radio-three">
是否可以有 2 组单选按钮共享一个 ID?我似乎无法让他们彼此友好相处。
演示:http://abenjamin765.github.io/slidemenu/
<input type="radio" name="set-one" id="radio-one">
<input type="radio" name="set-one" id="radio-two">
<input type="radio" name="set-one" id="radio-three">
<input type="radio" name="set-two" id="radio-one">
<input type="radio" name="set-two" id="radio-two">
<input type="radio" name="set-two" id="radio-three">
干杯!
没有。 ID 属性 必须 是唯一的。 ID 属性表示该单个元素的唯一标识。
来自HTML5 specification's id
attribute section:
3.2.5.1 The id attribute
The
id
attribute specifies its element's unique identifier (ID).The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character.
如果您想让它们共享一个引用(例如,出于样式目的),您可以改为使用 class
属性:
<input type="radio" name="set-one" class="radio-one">
<input type="radio" name="set-one" class="radio-two">
<input type="radio" name="set-one" class="radio-three">
<input type="radio" name="set-two" class="radio-one">
<input type="radio" name="set-two" class="radio-two">
<input type="radio" name="set-two" class="radio-three">