源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

AngularJS使用ng-class动态增减class样式的方法示例

  • 时间:2021-06-02 15:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:AngularJS使用ng-class动态增减class样式的方法示例
本文实例讲述了AngularJS使用ng-class动态增减class样式的方法。分享给大家供大家参考,具体如下: 使用[code]ng-class[/code]可以实现动态地增减样式:
<!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>

更多关于AngularJS相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/919.htm]AngularJS指令操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/893.htm]AngularJS入门与进阶教程[/url]》及《[url=http://www.1sucai.cn/Special/898.htm]AngularJS MVC架构总结[/url]》 希望本文所述对大家AngularJS程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部