gpt4 book ai didi

javascript - 在 Meteor-Angular 应用程序中动态更改背景 CSS

转载 作者:太空宇宙 更新时间:2023-11-04 11:10:51 26 4
gpt4 key购买 nike

我正在开发 AngularJS Ionic Meteor 应用程序,我需要根据其内容( float )更改 ionic 卡按钮框的背景颜色。范围是:

data<=80
81 < data <= 160
161 < data <= 233
234 < data<= 317
318 < data <= 400.

有没有一种 CSS 方式来做,或者 AngularJS 方式呢?

最佳答案

你可以使用 ngClass .只需设置您的 CSS 背景颜色属性并在您的 Controller 中设置适当的类,例如:

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {
$scope.submit = function() {
if ($scope.data <= 80) $scope.rangeColor = "red";
// Add more conditional statements
else $scope.rangeColor = "blue";
}
}
.card {
border-style: solid;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="myApp">
<div ng-controller="MyCtrl">
<h4>Data:</h4>
<form ng-submit="submit()">
<input type="text" name="data" ng-model="data" required>
<input type="submit" id="submit" value="Submit" />
</form>
<br />
<div ng-class="rangeColor" class="card">
<div class="item item-text-wrap">
This is a basic Card which contains an item that has wrapping text.
</div>
</div>
</div>
</body>

您还可以在 HTML 元素中实现条件语句:

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {

}
.card {
border-style: solid;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="myApp">
<div ng-controller="MyCtrl">
<h4>Data:</h4>
<input type="text" name="data" ng-model="data" required>
<br />
<br />
<div ng-class="{'red': data <= 80, 'blue': data > 80}" class="card">
<div class="item item-text-wrap">
This is a basic Card which contains an item that has wrapping text.
</div>
</div>
</div>
</body>

关于javascript - 在 Meteor-Angular 应用程序中动态更改背景 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33639124/

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