允许多选的 HTML 单选按钮 [英] HTML radio buttons allowing multiple selections

查看:26
本文介绍了允许多选的 HTML 单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 HTML 表单中,我有以下一组单选按钮,取决于您选择的单选按钮取决于下一个表单

显示的内容,这一切都有效.问题是出于某种原因,它们像复选框一样工作,而不是单选按钮.因此,您可以选择所有选项,而不仅仅是一次选择一个.

In my HTML form I have the below as a set of radio buttons, depending on what radio button you select depends on what the next form <fieldset> is revealed, this all works. The problem is for some reason they are working like a check box and not as a radio button. So you can select all options and not just the one at a time.

谁能看出下面代码中哪里出错了?

Can anyone see where this is going wrong in the code below?

  <fieldset>
        <legend>Please select one of the following</legend>
        <input type="radio" name="track" id="track" value="track" /><label for="track">Track Submission</label><br />
        <input type="radio" name="event" id="event" value="event"  /><label for="event">Events and Artist booking</label><br />
        <input type="radio" name="message" id="message" value="message" /><label for="message">Message us</label><br />
  </fieldset>

推荐答案

它们都需要具有 same name 属性.

They all need to have the same name attribute.

单选按钮按 name 属性分组.举个例子:

The radio buttons are grouped by the name attribute. Here's an example:

<fieldset>
    <legend>Please select one of the following</legend>
    <input type="radio" name="action" id="track" value="track" /><label for="track">Track Submission</label><br />
    <input type="radio" name="action" id="event" value="event"  /><label for="event">Events and Artist booking</label><br />
    <input type="radio" name="action" id="message" value="message" /><label for="message">Message us</label><br />
</fieldset>

这篇关于允许多选的 HTML 单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆