Rumah  >  Soal Jawab  >  teks badan

angular.js - 使用angular如何实现让checkbox单选,只能选择一个呢?

使用angular如何实现让checkbox单选,只能选择一个呢?

如图,以下是table中的checkbox选项:

<td width="30" style="text-align: left"><input
                            type="checkbox" ng-model="checkboxes.items[item.bookingId]" name="flag" ng-click="updateSelection(item.bookingId,checkboxes.items)"/></td>

如果在对象的controller里面实现,只能让其单选,选择一个呢??

習慣沉默習慣沉默2713 hari yang lalu577

membalas semua(2)saya akan balas

  • 迷茫

    迷茫2017-05-15 17:05:18

    kotak semak ialah kotak semak, sila gunakan radio

    untuk pilihan tunggal

    balas
    0
  • PHP中文网

    PHP中文网2017-05-15 17:05:18

    Cuba yang ini

    <p ng-controller="MyCtrl">
        <p ng-repeat="item in list">
            <label><input type="checkbox" ng-model="item.checked" ng-change="onChange(item)">{{item.name}}</label>
        </p>
    </p>
    .controller('MyCtrl', function ($scope) {
        $scope.selected = '';
        $scope.list = [
            {id: 1, name: 'xxx'},
            {id: 2, name: 'yyy'},
            {id: 3, name: 'zzz'}
        ];
    
        $scope.onChange = function (item) {
            if (item.checked) {
                if (!$scope.selected) $scope.selected = item;
                if ($scope.selected !== item) item.checked = false;
            } else {
                $scope.selected = '';
            }
        }
    });

    balas
    0
  • Batalbalas