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

标签 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>

最佳答案

名称属性必须相同才能一次只选择一个单选按钮。 id 可能会有所不同,具体取决于您是否要在某个地方捕获选择了哪个单选按钮的位置。

<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>

关于html - 无法一次选择一个单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18799533/

相关文章:

html - 如何使用 CSS 拆分网页?

javascript - 如果屏幕宽度小于 960 像素,则将屏幕宽度添加到类中

python - Django 中的 UpdateView 显示空白表单而不是数据库以前的数据

python - 如何抓取 HTML 的下一行

html - CSS - 链接排列不正确

html - 我怎样才能 "center"这个可变宽度菜单的子元素?

html - 如何使用 css/全屏幻灯片获得多个旋转背景封面

php - 使用 smarty 和 php 创建类别树

javascript - 光标 :move 时 firefox 表单不工作

html - 容器内的中心图像