angular修改标签css修改的三种方法

1:scope变量绑定

<div ng-app="index_app" ng-controller="index_controller">
	<button class="btn btn-default btn-lg" type="submit" ng-click="change_play_status3()">
		<span class="glyphicon {{play_status}}" aria-hidden="true"></span>
	</button>
</div>
<script>
	var index_app = angular.module('index_app', []);
	index_app.controller("index_controller",function($scope){
		$scope.play_status = "glyphicon-play";
		$scope.change_play_status3 =function(){
			if($scope.play_status == "glyphicon-play"){
				$scope.play_status = "glyphicon-pause"
			}else if($scope.play_status == "glyphicon-pause"){
				$scope.play_status = "glyphicon-play"
			}
		};
	});
</script>


2:字符串数组形式

<div ng-app="index_app" ng-controller="index_controller">	
	<button class="btn btn-default btn-lg" type="submit" ng-click="change_play_status()">
		<span class="glyphicon" ng-class="{true:'glyphicon-play',false:'glyphicon-pause'}[isPlay]" aria-hidden="true"></span>
	</button>
</div>
<script>	
	var index_app = angular.module('index_app', []);
	index_app.controller("index_controller",function($scope){
		$scope.isPlay = false;
		$scope.change_play_status = function(){
			$scope.isPlay = !$scope.isPlay;
		};
	});
</script>
3:对象key/value处理

<div ng-app="index_app" ng-controller="index_controller">
	<button class="btn btn-default btn-lg" type="submit" ng-click="change_play_status2()">
		<span class="glyphicon" ng-class="{'glyphicon-play':isPlay2,'glyphicon-pause':isPause2}" aria-hidden="true"></span>
	</button>
</div>
<script>	
	var index_app = angular.module('index_app', []);
	index_app.controller("index_controller",function($scope){
		$scope.isPlay2 = false;
		$scope.isPause2 = true;
		$scope.change_play_status2 =function(){
			$scope.isPlay2 = !$scope.isPlay2;
			$scope.isPause2 = !$scope.isPause2;
		};
	});
</script>



  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值