【发布时间】:2021-08-23 22:03:47
【问题描述】:
当检查输入单选时,我需要将 div 的背景更改为不同的颜色。我在我的开发工具中注意到,当我单击单选按钮时,html 不会将选中的标记添加到输入中。我打算做一些类似 input[type=radio]:checked + label 的事情来应用这个方法。如果 html 没有应用选中的方法,我确定这不起作用吗?一旦用户点击它,我如何让输入单选应用选中的属性?
<main class="subscription__container">
<section
id="preferences"
class="subscription__container--preferences box"
>
<div class="question__container">
<h3 class="question__container--title">
How do you drink your coffee?
</h3>
<img
class="question__container--img"
src="../assets/plan/desktop/icon-arrow.svg"
alt="arrow"
/>
</div>
<div class="options__container">
<div class="options__container--option">
<input
id="capsule"
type="radio"
data-preference="Capsule"
value="Capsule"
name="preferences"
/>
<label class="test__trail" for="capsule">
<h4 class="options__container--title">Capsule</h4>
<p class="options__container--description">
Compatible with Nespresso systems and similar brewers.
</p>
</label>
</div>
<div class="options__container--option">
<input
id="filter"
type="radio"
data-preference="Filter"
value="Filter"
name="preferences"
/>
<label class="test__trail" for="filter">
<h4 class="options__container--title">Filter</h4>
<p class="options__container--description">
For pour over or drip methods like Aeropress, Chemex, and V60.
</p>
</label>
</div>
<div class="options__container--option">
<input
id="espresso"
type="radio"
data-preference="Espresso"
value="Espresso"
name="preferences"
/>
<label class="test__trail" for="espresso">
<h4 class="options__container--title">Espresso</h4>
<p class="options__container--description">
Dense and finely ground beans for an intense, flavorful
experience.
</p>
</label>
</div>
</div>
</section>
【问题讨论】: