angularjs怎么跳回下拉框选中的页面
展开全部
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<script type="text/javascript" src="angular.min.js"></script>
<script>
var myApp = angular.module("myApp", []);
myApp.controller("testCtrl", function($scope){
$scope.data = [{id:1,value:'hello'},{id:2,value:'bye'},{id:3,value:'hmmmm'}];
//$scope.selectValue = $scope.data[0].id;
});
</script>
</head>
<body ng-app="myApp">
<form ng-controller="testCtrl">
<select ng-model="selectValue" ng-options="item.id as item.value for item in data"></select><br /><br />
<div ng-switch="selectValue">
<div ng-switch-when="1">hello</div>
<div ng-switch-when="2">bye</div>
<div ng-switch-when="3">hmmmm</div>
<div ng-switch-default>ah?</div>
</div>
</form>
</body>
</html>
也可以不用switch用ng-show/hide或者ng-if这样的。
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<script type="text/javascript" src="angular.min.js"></script>
<script>
var myApp = angular.module("myApp", []);
myApp.controller("testCtrl", function($scope){
$scope.data = [{id:1,value:'hello'},{id:2,value:'bye'},{id:3,value:'hmmmm'}];
//$scope.selectValue = $scope.data[0].id;
});
</script>
</head>
<body ng-app="myApp">
<form ng-controller="testCtrl">
<select ng-model="selectValue" ng-options="item.id as item.value for item in data"></select><br /><br />
<div ng-switch="selectValue">
<div ng-switch-when="1">hello</div>
<div ng-switch-when="2">bye</div>
<div ng-switch-when="3">hmmmm</div>
<div ng-switch-default>ah?</div>
</div>
</form>
</body>
</html>
也可以不用switch用ng-show/hide或者ng-if这样的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询