扫码关注官方订阅号
使用angular如何实现让checkbox单选,只能选择一个呢?
如图,以下是table中的checkbox选项:
如果在对象的controller里面实现,只能让其单选,选择一个呢??
checkbox是复选框,单选请用radio
试试这个呢
<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 = ''; } } });
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
checkbox是复选框,单选请用radio
试试这个呢