AngularJS使用ng-class动态增减class样式的方法示例
更新时间:2017年05月18日 11:44:48 作者:itsonglin
这篇文章主要介绍了AngularJS使用ng-class动态增减class样式的方法,结合具体实例形式分析了ng-class操作页面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>
更多关于AngularJS相关内容感兴趣的读者可查看本站专题:《AngularJS指令操作技巧总结》、《AngularJS入门与进阶教程》及《AngularJS MVC架构总结》
希望本文所述对大家AngularJS程序设计有所帮助。
相关文章
AngularJS控制器controller正确的通信的方法
AngularJS中的controller是个函数,用来向视图的作用域($scope)添加额外的功能,我们用它来给作用域对象设置初始状态,并添加自定义行为2016-01-01
angularJs中跳转到指定的锚点实例($anchorScroll)
今天小编就为大家分享一篇angularJs中跳转到指定的锚点实例($anchorScroll),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-08-08
Angular Component属性绑定target和attr.target的区别分析
这篇文章主要介绍了Angular Component属性绑定target和attr.target的区别分析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-07-07


最新评论