<input type="radio" name="allotdeallot" value="Allotment" />Allotment
<input type="radio" name="allotdeallot" value="De-Allotment" />De-Allotment
我有两个单选按钮,我想在标签点击时检查或取消选中。
答案 0 :(得分:1)
使用<label>
代码并将id
属性添加到radio
按钮:
<input type="radio" name="allotdeallot" id="allotment" value="Allotment" /><label for="allotment">Allotment</label>
<input type="radio" name="allotdeallot" id="deallotment" value="De-Allotment" /><label for="deallotment">De-Allotment</label>
答案 1 :(得分:0)
根据HTML标准,每个表单元素都必须附加label
。您希望隐藏标签文字,可以使用lable
隐藏position:absolute
的文字label
。所以这是你的答案,
<input id="allotment" type="radio" name="allotdeallot" value="Allotment" /><label for="allotment">Allotment</label>
<input id="de-allotment" type="radio" name="allotdeallot" value="De-Allotment" /><label for="de-allotment">De-Allotment</label>
id of the input field
必须与for attribute of the label
相同。