且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单击文本以选择相应的单选按钮

更新时间:1970-01-01 07:56:48

在代码中,您在表单本身上有一个标签。您想要为每个单独的广播组添加标签,如下所示。

In your code, you've got a label on the form itself. You want to put labels on each individual radio group, as shown below.

<form>
    <p>What is my middle name?</p>
    <br>
    <input id="349" type="radio" value="1" name="question1">
    <label for="349">Abe</label>
    <br>
    <input id="350" type="radio" value="2" name="question1">
    <label for="350">Andrew</label>
    <br>
    <input id="351" type="radio" value="3" name="question1">
    <label for="351">Andre</label>
    <br>
    <input id="352" type="radio" value="4" name="question1">
    <label for="352">Anderson</label>
    <br>
</form>

Live example

您应该记住,两个元素不应该具有相同的ID。使用 name 属性,使单选按钮作为一个组,并且一次只允许单个选择。

You should keep in mind that two elements should never have the same ID. The name attribute is used so that the radio buttons function as a group and only allow a single selection at a time.