我很好奇如何为类添加到父div
为<input type="radio">
对单选按钮组?
代码在下面,JSFiddle在这里
HTML:
<div class="bd"> <input type="radio" ng-model="value" value="foo" ng-change='newValue(value)'></div>
<div class="bd active"><input type="radio" ng-model="value" value="bar" ng-change='newValue(value)'></div>
<div class="bd"><input type="radio" ng-model="value" value="baz" ng-change='newValue(value)'> </div>
<hr>
</div>
JS:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.value= 'foo';
$scope.newValue = function(value) {
console.log(value);
}
}
CSS:
.bd {
border:1px solid red;
width:100px;
float:left;
}
.active{
border:1px solid green;
}
您可以使用ng-class指令来做到这一点:
<div ng-class="{'active': value=='foo'}" ...>
这是更新的小提琴:http : //jsfiddle.net/6urevw2t/2/
希望能帮助到你,
问候
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句