css - 两组具有独立行为的不同单选按钮

标签 css html radio-button

我有两个不同的部分,由两个具有不同值和 ID 的单选按钮组成。问题是我一次只能检查一个按钮,但我需要这两组单选按钮独立工作,即在每组单选按钮中可以检查一个按钮。 这是 HTML:

<section class="radio_holder_1">
    <div class="radio">
        <input id="share_this" type="radio" name="option_type" value="share_this" checked>
        <label class="hmc_radiolabel" for="share_this">Share Picture</label>
        <input id="use_4_now" type="radio" name="option_type" value="use_4_now">
        <label class="hmc_radiolabel" for="use_4_now">Instant Use</label>
    </div>
</section>
    <hr>
<section class="radio_holder_2">
    <div class="radio_2">
       <input id="free" type="radio" name="option_type" value="free" checked>
       <label class="hmc_radiolabel" for="free">FREE</label>
       <input id="premium" type="radio" name="option_type" value="premium">
       <label class="hmc_radiolabel" for="premium">VIP</label>
    </div>
</section>

最佳答案

问题是你的名字。为第二个选择使用不同的名称,它应该可以工作。

<section class="radio_holder_1">
<div class="radio">
<input id="share_this" type="radio" name="option_type" value="share_this" checked>
<label class="hmc_radiolabel" for="share_this">Share Picture</label>
<input id="use_4_now" type="radio" name="option_type" value="use_4_now">
<label class="hmc_radiolabel" for="use_4_now">Instant Use</label>
</div>
</section>
<hr>
<section class="radio_holder_2">
<div class="radio_2">
<input id="free" type="radio" name="option_type2" value="free" checked>
<label class="hmc_radiolabel" for="free">FREE</label>
<input id="premium" type="radio" name="option_type2" value="premium">
<label class="hmc_radiolabel" for="premium">VIP</label>
</div>
</section>

关于css - 两组具有独立行为的不同单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33972766/

相关文章:

html - 为什么我的文本在我的 CSS 导航栏的中间不是垂直的?

html - 链接内的图像在悬停时有颜色叠加

html - 如何将自定义字段添加到 Woocommerce 中的类别?

c# - 如何使用 HTML Agility Pack 清理格式错误的 HTML

c# - 将多个元素放入 WPF 中的 GroupBox 中

css - 需要帮助修复 Gnome Shell 的 GTK 主题的 CSS

javascript - 在加载时使用 javascript 添加样式属性

javascript - 使 div-section 出现基于事件

html - 让两个单选按钮表现为一个复选框

javascript - 在 React 中设置单选按钮值