【发布时间】:2020-11-28 13:03:02
【问题描述】:
Meteor 中的这段代码需要在单击时将背景颜色更改为黄色,在再次单击时将背景颜色更改为白色,我在阅读其他解决方案后尝试了几种方法,但无法使其正常工作。
如果是白色,如何将颜色更改为黄色,如果是黄色,如何更改为白色。稍后我还需要在条件语句中编写其他内容。
HTML 是:
<p>{{car.carID}} <strong class="toggleBackground">{{car.plate}}</strong></P>
谢谢
'click .toggleBackground': (e) => {
//$(e.target).addClass('yellow'); // tried with css file for no avail
console.log($(e.target).css("background-color"));
//tried === rgba(255, 255, 0) instead of yellow for no avail
if($(e.target).css('background-color') === 'yellow'){ //<<< never true
console.log('already yellow'); //<<< never called
$(e.target).css('background-color', 'white');
} else {
console.log('will make yellow');
$(e.target).css('background-color', 'yellow');
}
}
.white{
background-color: #FFFFFF
}
.red{
background-color: yellow
}
【问题讨论】:
标签: javascript html css meteor