forked from hamger/hg-citypicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
112 lines (101 loc) · 2.77 KB
/
index.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<meta name="screen-orientation" content="portrait" />
<title>hg-citypicker</title>
<link rel="shortcut icon" href="http://olislpb6q.bkt.clouddn.com/hg-head.png" />
<link rel="stylesheet" type="text/css" href="./picker.css" />
<style>
* {
padding: 0;
margin: 0;
}
body {
background-color: #fff;
}
.wraper {
margin-bottom: 15px;
}
.title {
position: relative;
width: 100%;
height: 48px;
line-height: 48px;
text-align: center;
color: #000;
}
.title:after {
content: '';
position: absolute;
width: 100px;
height: 5px;
left: 48%;
bottom: 0;
margin: 0 -42px;
background: #bbb;
border-radius: 10px;
}
.inputDiv {
color: #333;
width: 200px;
height: 20px;
line-height: 20px;
margin: 10px auto;
padding: 5px 20px;
border: 1px solid #bbb;
border-radius: 8px;
}
.btn-box {
text-align: center;
}
.btn {
line-height: 20px;
padding:0 3px;
border: 1px solid #000;
}
</style>
</head>
<body>
<article class="wraper">
<h3 class="title">cityPicker1</h3>
<div onclick="select(1)" class="inputDiv" id="city-input1">选择中国城市</div>
<h3 class="title">cityPicker2</h3>
<div onclick="select(2)" class="inputDiv" id="city-input2">选择中国城市</div>
<div class="btn-box">
<button class="btn" onclick="setInitailOption()">设置初始显示</button>
</div>
</article>
<script src="./city.js"></script>
<script src="./dist/hg-citypicker.js"></script>
<script>
var picker = new CityPicker({
data: city, // 符合格式的数组
cancel: function () {
console.log('取消城市选择');
},
initValue: ['辽宁', '大连', '中山区'],
onOk: function(arr) {
console.log(arr);
var arr2 = [];
arr.forEach(function(val) {
arr2.push(val.value);
});
document.getElementById('city-input' + this.get('pickerNumber')).innerHTML = arr2;
}
});
function setInitailOption () {
picker.set({initValue: ['湖北', '荆州', '荆州区']})
}
function select (number) {
picker.set({
pickerNumber: number,
title: number + '号选择器'
});
picker.show()
}
</script>
</body>
</html>