AngularJS使用ng-class動態增減class樣式的方法樣本,angularjsng-class

來源:互聯網
上載者:User

AngularJS使用ng-class動態增減class樣式的方法樣本,angularjsng-class

本文執行個體講述了AngularJS使用ng-class動態增減class樣式的方法。分享給大家供大家參考,具體如下:

使用ng-class可以實現動態地增減樣式:

<!DOCTYPE html><html ng-app="formExample"><head>  <meta charset="UTF-8">  <title></title>  <script src="../js/angular.js"></script>  <script>    angular.module('formExample', [])        .controller('FormController', ['$scope', function($scope)        {        }]);  </script>  <style>    .strike {      text-decoration: line-through;    }    .bold {      font-weight: bold;    }    .red {      color: red;    }  </style></head><body><div>  <p ng-class="{strike: deleted, bold: important, red: error}">通過映射的方式</p>  <input type="checkbox" ng-model="deleted">添加strike樣式<br>  <input type="checkbox" ng-model="important">添加bold樣式<br>  <input type="checkbox" ng-model="error">添加錯誤樣式  <hr>  <p ng-class="style">使用字串的方式</p>  <input type="text" ng-model="style" placeholder="輸入 bold、 strike 或 red">  <hr>  <p ng-class="[style1, style2, style3]">使用數組的方式</p>  <input ng-model="style1" placeholder="輸入: bold, strike 或 red"><br>  <input ng-model="style2" placeholder="輸入: bold, strike 或 red"><br>  <input ng-model="style3" placeholder="輸入: bold, strike 或 red"><br>  <hr/></div></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.