无法一次选择一个单选按钮

时间:2013-09-14 07:44:42

标签: html

我无法一次选择一个单选按钮。正在选择多个按钮。我是html的新手。这是我的代码。请帮忙。

<form name="ans_a" onsubmit="return answer_a()">
    <table align="center" border="1">
        <br>
        <br>
        <tr>
            <td width="500px"> ABC 
                <br>
                <input type="radio" name="A" value="a" id="radio1"> A &nbsp Option A <br>
                <input type="radio" name="B" value="b" id="radio2"> B &nbsp Option B <br>
                <input type="radio" name="C" value="c" id="radio3"> C &nbsp Option C <br>
                <input type="radio" name="D" value="d" id="radio4"> D &nbsp Option D <br>
                <br>
                &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                <input type="button" name="ans1" value="Next" onclick="answer_a()">
            </td>
        </tr>
    </table>
</form>

3 个答案:

答案 0 :(得分:8)

要仅选择一个广播button,您必须为每个name按钮设置相同的radio

<input type="radio" name="A" value="a" id="radio1"> A &nbsp Option A <br>
<input type="radio" name="A" value="b" id="radio2"> B &nbsp Option B <br>
<input type="radio" name="A" value="c" id="radio3"> C &nbsp Option C <br>
<input type="radio" name="A" value="d" id="radio4"> D &nbsp Option D <br>

答案 1 :(得分:2)

要只选择一个单选按钮,您必须将它们放在一个组中,即使所有这些单元的名称属性相同。

<input type="radio" name="options" value="a" id="radio1"> A &nbsp Option A <br>
<input type="radio" name="options" value="b" id="radio2"> B &nbsp Option B <br>
<input type="radio" name="options" value="c" id="radio3"> C &nbsp Option C <br>
<input type="radio" name="options" value="d" id="radio4"> D &nbsp Option D <br>

答案 2 :(得分:0)

为我在项目中这样使用的所有单选按钮尝试相同的名称

 <div class="col-md-2">   <label><input type="radio" class="classone" name="A">Daily</label> </div>
 <div class="col-md-2">   <label><input type="radio" class="classone" name="A">Weekly</label> </div>
 <div class="col-md-2">   <label><input type="radio" class="classone" name="A">Monthly</label> </div>
 <div class="col-md-2">   <label><input type="radio" class="classone" name="A">Yearly</label> </div>