从下拉菜单中选择独特的选项?

时间:2015-04-10 06:32:09

标签: javascript angularjs drop-down-menu

我有一个html页面,其中包含10个下拉列表,每个下拉列表都有1到10个选项。 如何为所有下拉菜单唯一分配选项。如果我从下拉列表1中选择1,那么该特定选项将从其他下拉列表中删除。 如果我对任何人进行了选择,那么在下拉选项中再次添加了该特定下拉列表的数量。

1 个答案:

答案 0 :(得分:0)

看一下这段代码:

HTML:

<div ng-controller="MyCtrl">
<select ng-model='selectedNumber' ng-change="adv(selectedNumber);" ng-options='number for number in numbers'></select>
num:   {{selectedNumber}}
<select ng-model='selected' ng-options="number for number in num"></select>
num:   {{selected}}
<button ng-click="add()" >add</button>
</div>

JS:

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {    
  $scope.numbers = [1,2,3,4,5,6,7,8,9,10];
  $scope.num = angular.copy($scope.numbers);
  $scope.selectedNumber = $scope.numbers[0];
  //$scope.selected = $scope.num[0];

  $scope.add=function(){
  $scope.num = angular.copy($scope.numbers);
}

 $scope.adv = function(selectedNumber){
 $scope.num = angular.copy($scope.numbers);
 // $scope.selected = $scope.numbers[selectedNumber];   
 var a = $scope.num.splice(selectedNumber-1, 1);  
}

 $scope.num = angular.copy($scope.numbers);
} 

希望这是你想要的那个。