在单选按钮上使用"label for“参数为508 compliant*时,以下内容是否正确?
<label for="button one"><input type="radio" name="group1" id="r1" value="1" /> button one</label>
或者这是什么?
<input type="radio" name="group1" id="r1" value="1" /><label for="button one"> button one</label>
我问的原因是,在第二个示例中,"label“只包含文本,而不是实际的单选按钮。
*1973年“康复法”第508条要求联邦机构向残疾人提供软件和网站访问。
发布于 2009-10-06 19:55:38
你差一点就成功了。应该是这样的:
<input type="radio" name="group1" id="r1" value="1" />
<label for="r1"> button one</label>
for
中的值应该是要标记的元素的id。
发布于 2009-10-06 20:03:47
这两个结构都是有效且可访问的,但for
属性应等于输入元素的id
:
<input type="radio" ... id="r1" /><label for="r1">button text</label>
或
<label for="r1"><input type="radio" ... id="r1" />button text</label>
在第二个版本中,for
属性是可选的(标签包含输入),但是有一些较旧的浏览器不能使标签文本可点击,除非您将其包括在内。第一个版本(输入后的标签)更容易使用相邻的兄弟选择器+
设置样式
input[type="radio"]:checked+label {font-weight:bold;}
发布于 2019-04-24 05:02:04
(首先阅读解释了<label></label>
标签中for
的其他答案。好吧,上面两个答案都是正确的,但我的挑战是,当你有几个单选框时,你应该为它们选择一个像name="r1"
但ids不同的通用名称 id="r1_1" ... id="r1_2"
因此,这种方式的答案更明确,也消除了名称和ids之间的冲突。
您需要为单选框的不同选项提供不同的ids。
<input type="radio" name="r1" id="r1_1" />
<label for="r1_1">button text one</label>
<br/>
<input type="radio" name="r1" id="r1_2" />
<label for="r1_2">button text two</label>
<br/>
<input type="radio" name="r1" id="r1_3" />
<label for="r1_3">button text three</label>
https://stackoverflow.com/questions/1527721
复制相似问题