angularjs獲取check框選中的值

html:

<div><input type="checkbox" ng-click="updateSelection($event,row.entity.id)" ng-checked="isSelected(row.entity.id)">選擇</div>

 js:

$scope.selected = [];
$scope.updateSelection = function (event, id) {
    var checkbox = event.target;
    var action = (checkbox.checked ? 'add' : 'remove');
    if (action == 'add' && $scope.selected.indexOf(id) == -1) {
        $scope.selected.push(id);
    }
    if (action == 'remove' && $scope.selected.indexOf(id) != -1) {
        var idx = $scope.selected.indexOf(id);
        $scope.selected.splice(idx, 1);
    }

    console.log($scope.selected)

}
$scope.isSelected = function(id){
     return $scope.selected.indexOf(id)>=0;
 }

參考:https://blog.csdn.net/liaodehong/article/details/50531873

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章