Javascript 如何在数组中的三个不同变量之间切换?
3个条件如何来回切换?谢谢 基本上我有一个下拉菜单,其中有三个不同的名字,每个名字都有自己的解释Javascript 如何在数组中的三个不同变量之间切换?,javascript,Javascript,3个条件如何来回切换?谢谢 基本上我有一个下拉菜单,其中有三个不同的名字,每个名字都有自己的解释 $scope.dropDownMenu = ["East","West","Central"]; $scope.selectedItem = $scope.dropDownMenu[0]; if($scope.selectedItem === "East") $scope.selectedItem = $scope.dropDownMenu[1];
$scope.dropDownMenu = ["East","West","Central"];
$scope.selectedItem = $scope.dropDownMenu[0];
if($scope.selectedItem === "East")
$scope.selectedItem = $scope.dropDownMenu[1];
and so on.....
在数组中很容易在变量之间切换,但三个?我真的不知道怎么做
跟踪索引
function toggle() {
var nextIndex = $scope.currentIndex + 1;
if (nextIndex >= $scope.dropDownMenu.length) {
nextIndex = 0;
}
$scope.selectedItem = $scope.dropDownMenu[nextIndex];
$scope.currentIndex = nextIndex;
}
谢谢你的帮助,凯尔