如果本文对您有帮助,希望点个赞,建立下友谊关系。

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 + '.&nbsp&nbsp' + scene.name}}</a>
</li>

js:

$scope.setColor = function (isgreet) {
        var p = "";
        if (isgreet == false) {
            p = '#9dd4f1';
        } else {
            p = '#bbf5b3';
        }
        return { "background-color": p };
    };

 

posted @ 2017-12-15 13:40  一只喵喵  阅读(814)  评论(0编辑  收藏  举报