AngularJS ng-class-odd 指令

返回到:AngularJS 参考手册

定义和用法

ng-class-odd 指令用于为 HTML 元素动态的绑定一个或多个 CSS 类,但只作用于奇数行。

ng-class-odd 指令需要与 ng-repeat 指令搭配使用。

ng-class-odd 指令建议用在表格的样式渲染中,但是所有HTML元素都是支持的。

语法

<element ng-class-odd="expression"></element>

所有 HTML 元素都支持。

参数值

描述
expression表达指定一个或多个 CSS 类。

AngularJS 实例

为表格的奇数行设置 class=”striped”:

<!DOCTYPE html>
<html>
<head>
	<title>AngularJS 实例 | Web176教程网web176.com</title>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
<style>
.striped {
    color:white;
    background-color:black;
}
</style>
</head>
<body ng-app="myApp">

<table ng-controller="myCtrl">
<tr ng-repeat="x in records" ng-class-odd="'striped'">
  <td>{{x.Name}}</td>
  <td>{{x.Country}}</td>
</tr>
</table>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [
    {
      "Name" : "Alfreds Futterkiste",
      "Country" : "Germany"
    },
    {
      "Name" : "Berglunds snabbk",
      "Country" : "Sweden"
    },
    {
      "Name" : "Centro comercial Moctezuma",
      "Country" : "Mexico"
    },
    {
      "Name" : "Ernst Handel",
      "Country" : "Austria"
    }
  ]
});
</script>

</body>
</html>

作者:terry,如若转载,请注明出处:https://www.web176.com/angularjsapi/6339.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2022年8月11日 上午10:37
下一篇 2022年8月11日 上午10:42

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注