当我点击其他任何地方按钮失去选择时,我需要帮助,以便在我点击其他任何地方时保持选中状态

时间:2016-05-31 12:59:20

标签: javascript html css angularjs

$scope.isVisible = false;

$scope.selectionCheck = function () {
    if ($scope.printer1 != undefined) {
           if ($scope.printer1.isSelected == true) {    
                return 'selected';
           } else {
                return 'normalclass';
           }
    }
    // I wanted to remain selected
    if ($scope.printer2 != undefined) {
        if ($scope.printer2.isSelected == true) {
            return 'selected';                    
        } else {
            return 'normalclass';
        }
    }
};
.normalclass {
    background: lightgrey;
    color: white;
}
<div ng-show="printer1Visible">
    <button ng-class="{'selected': 'printer1.isSelected'}" 
ngclick="tryit(printer1)" style="margin-bottom: 20px;" class="normalclass btn btn-success btn-lg">{{printer1.printerName}}{{selected1}}</button><br />
</div>

<div ng-show="printer2Visible">
    <button style="margin-bottom: 20px;" ng-class="{'selected': 'printer2.isSelected'}" ng-click="tryit(printer2)" class=" normalclass btn btn-success btn-lg"> {{printer2.printerName}}{{selected2}}</button>    

    <br />
</div>

0 个答案:

没有答案