hg-citypicker
Version:
a citypicker in the mobile terminal
113 lines (101 loc) • 2.83 kB
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>