-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselect三级联动默认选择
68 lines (59 loc) · 2.41 KB
/
select三级联动默认选择
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html ng-app="app">
<head>
<meta charset="UTF-8">
<title>angularjs</title>
<style type="text/css">
.icon-tick {
background-color: red;
}
.icon-loops {
background-color: gray;
}
</style>
</head>
<body ng-controller="customerCtr">
<hr/>
<select class="form-control formSelect" name="province" ng-model="regData.province" ng-options="province.province_name for province in selectArea" required>
<option value="">请选择省</option>
</select>
<select class="form-control formSelect" name="city" ng-model="regData.city" ng-options="city.city_name for city in regData.province.cityItems" required>
<option value="">请选择市</option>
</select>
<select class="form-control formSelect" name="district" ng-model="regData.district" ng-options="district.town_name for district in regData.city.items" required>
<option value="">请选择区</option>
</select>
<script src="http://192.168.0.118/git/car2go_h5/Buyers_htmlV3.0/resource/AngularJS/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('customerCtr', [
var regData = $scope.regData = {};
//地区json文件加载
traVal.areasFn(function(res, status, headers, config) {
$scope.selectArea = res;
console.log(res)
//设置默认省
angular.forEach($scope.selectArea, function(val, key) {
if(val.province_id == '440000'){
regData.province = val;
}
})
//设置默认市
angular.forEach(regData.province.cityItems, function(val, key) {
if(val.city_id == '440100'){
regData.city = val;
}
})
//设置默认区
angular.forEach(regData.city.items, function(val, key) {
if(val.town_id == '440103'){
regData.district = val;
}
})
}, function(res, status, headers, config) {
console.log("地区文件加载失败");
})
]);
</script>
</body>
</html>