[英]Change Buttons when Clicked
Below is my HTML code with Bootstrap and Angular: 下面是我的带有Bootstrap和Angular的HTML代码:
<button class="btn btn-secondary btn-sm" ng-click="buy(player)">{{history.indexOf(player)>=0?'REMOVE':'SELECT'}}</button>
When i click the button, the wording of the button changes from 'SELECT' to 'REMOVE'. 当我单击按钮时,按钮的措词从“选择”更改为“删除”。 However, what i want is the colour of the button to change so that it is the default colour when on 'SELECT' but the red "btn-danger" class when 'REMOVE'. 但是,我想要的是更改按钮的颜色,以便在“选择”时它是默认颜色,而在“删除”时它是红色的“ btn-danger”类。
Is this possible? 这可能吗?
Sure! 当然! And it's really simple. 这真的很简单。
<button class="btn btn-secondary btn-sm" ng-class="{'btn-danger': history.indexOf(player) >= 0 }" ng-click="buy(player)">{{history.indexOf(player)>=0?'REMOVE':'SELECT'}}</button>
Note ng-class directive added to the button. 注意ng-class指令已添加到按钮中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.