![](/img/trans.png)
[英]Why isn't my onclick event listener on my radio buttons not working?
[英]Why isn't :checked working for my radio buttons?
所以我創建了一個測驗表單並想更改單選按鈕的樣式,我確實這樣做了,但是現在您無法判斷何時選擇了一個選項,但答案仍在記錄中。 如何使所選選項更改背景顏色?
這是一個問題的 HTML:
<div class="form-group">
<label
>{{ quizQuestions[0] }}
<div class="radio" *ngFor="let flavor of answerSetOne">
<label id="radio">
<input
checked
type="radio"
name="flavor"
class="btn-check"
ngModel [value]="flavor.num"
required/>
{{ flavor.name | titlecase}}
</label>
</div>
</label>
</div>
我認為應該可以使用的 CSS :
opacity: 0;
position: fixed;
width: 0;
}
.radio label {
display: inline-block;
background-color: rgb(248, 174, 89);
padding: 10px 20px;
font-size: 14px;
border-radius: 4px;
}
.radio input[type=radio]:checked + label {
background-color:rgb(114, 31, 6);
}
```an
在您的 css 中,您需要引用您的類型:
.radio input[type="radio"]:checked + label {
opacity: 0; position: fixed; width: 0; }.radio label { display: inline-block; background-color: rgb(248, 174, 89); padding: 10px 20px; font-size: 14px; border-radius: 4px; }.radio input[type="radio"]:checked + label { background-color:rgb(114, 31, 6); }
<div class="form-group"> <label >{{ quizQuestions[0] }} <div class="radio" *ngFor="let flavor of answerSetOne"> <label id="radio"> <input checked type="radio" name="flavor" class="btn-check" ngModel [value]="flavor.num" required/> {{ flavor.name | titlecase}} </label> </div> </label> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.