[英]Find out if there are selected more than one on Checkbox
這就是我有一個復選框的方式,它必須是這樣的,例如,當我單擊我的按鈕時,因此一定要知道必須有多個復選框。 因此,它總共必須具有更多價值。
現在,在console.log()中沒有給出錯誤或成功消息。
<input type="checkbox"
ng-checked="ItemSelected"
name="SelectedTypes"
value="2" />
<input type="checkbox"
ng-checked="ItemSelected"
name="SelectedTypes"
value="3" />
<input type="checkbox"
ng-checked="ItemSelected"
name="SelectedTypes"
value="4" />
<input type="button" class="btn btn-success" value="Næste" ng-click="UppersViewClick()" />
CreateUserInfo.js-文件
$scope.UppersViewClick = function ()
{
if ($scope.ItemSelected !== undefined)
{
if ($scope.ItemSelected.length > 1) {
$scope.UppersViewInfo = false;
$scope.PantsViewInfo = true;
console.log("succes")
}
else
{
console.log("error");
}
}
}
因此,目的是要確保我從中獲得一個或多個價值。
您無法獲得這樣的復選框,因為所有復選框均指代同一型號,
$scope.records = [ { "Id": 1 }, { "Id": 2 }, { "Id": 3 } ];
演示
var app = angular.module('plunker', []); app.controller('MyCtrl', function($scope) { $scope.records = [ { "Id": 1 }, { "Id": 2 }, { "Id": 3 } ]; $scope.selected = {}; $scope.ShowSelected = function() { $scope.records = $.grep($scope.records, function( record ) { return $scope.selected[ record.Id ]; }); }; });
<!doctype html> <html ng-app="plunker" > <head> <meta charset="utf-8"> <title>AngularJS Plunker</title> <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet"> <link rel="stylesheet" href="style.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> <script src="https://raw.github.com/twitter/bootstrap/master/docs/assets/js/bootstrap.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script> <script src="https://raw.github.com/angular-ui/angular-ui/master/build/angular-ui.js"></script> <script src="app.js"></script> </head> <body> <div data-ng-controller="MyCtrl"> <ul> <li data-ng-repeat="record in records"> <input type="checkbox" ng-model="selected[record.Id]"> {{record.Id}} </li> </ul> <a href="javascript:;" data-ng-click="ShowSelected()">Show Selected</a> </div> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.