angularJS判断一个checkBox选中传值和更改颜色
1、给复选框赋值
HTML:
<label><input type="checkbox" ng-model="isGreet">是否打招呼?</label>
js部分:(只写个给数据赋值的方法,添加修改的时候只需要传$scope.isGreet就行了)
$scope.isGreet = false; //是否打招呼 $scope.sceneEdit = function (item) {//item为点击的某一行的所有数据 $scope.visibal = true; $scope.visibals = true; $scope.scene = item.name; $scope.sceneUpdataData = item; if (item.isgreet == false) { $scope.isGreet = false; } else { $scope.isGreet = true; } $("html, body").animate({ scrollTop: ($("#scene").offset().top - 50) }, { duration: 500, easing: "swing" }); $('.focus-scene').focus(); }
2、根据获取的数据改变其颜色:
html:
<li ng-repeat="scene in scenedata"> <a ng-style="setColor(scene.isgreet)" class="a-title" ng-click="dropDown($event, scene.id)">{{$index+1 + '.  ' + scene.name}}</a> </li>
js:
$scope.setColor = function (isgreet) { var p = ""; if (isgreet == false) { p = '#9dd4f1'; } else { p = '#bbf5b3'; } return { "background-color": p }; };