gpt4 book ai didi

javascript - ionic 2 : Add Class to Item While Removing Class From Other Items

转载 作者:太空狗 更新时间:2023-10-29 18:30:55 25 4
gpt4 key购买 nike

我有一个充满按钮的 div,单击这些按钮时,应该添加一个类 (selected-date-item) 来更改按钮的颜色。紧接着,我想从之前拥有该类的任何按钮中删除该类 (selected-date-item)。

CSS

.selected-date-item {
background:#272829;
color:white;
}

HTML

<button class="date-time-select" *ngFor="let chooseDate of possibleDates" (tap)="selectPickupDate(chooseDate)">{{chooseDate}}</button>

JS

selectPickupDate(selectedDate) {
this.selectedDate = selectedDate;
}

enter image description here => enter image description here

最佳答案

使用 [ngClass] 指令动态设置 CSS 类。

<button [ngClass]="{'selected-date-item': chooseDate == selectedDate, 'not-selected-item': chooseDate != selectedDate}" *ngFor="let chooseDate of possibleDates" (tap)="selectPickupDate(chooseDate)">{{chooseDate}}</button>

[ngClass] 分解:

[ngClass]="{'selected-date-item': chooseDate == selectedDate, 'not-selected-item': chooseDate != selectedDate}"

关于javascript - ionic 2 : Add Class to Item While Removing Class From Other Items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45338390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com