项目效果如图所示
核心js代码如下
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<SCRIPT src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></SCRIPT>
$('#showDatePicker').on('click', function () {
weui.datePicker({
start: 1900,
end: new Date().getFullYear(),
onChange: function (result) {
var seperator="-";
var year = result[0];
var month = result[1];
var strDate = result[2];
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var resultDate = year + seperator + month + seperator + strDate;
$('#showDatePicker').val(resultDate);
//$(showDatePicker).val(resultDate);
console.log(result);
},
onConfirm: function (result) {
var year = result[0];
var month = result[1];
var strDate = result[2];
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var resultDate = year + seperator + month + seperator + strDate;
$('#showDatePicker').val(resultDate);
console.log(result);
}
});
});
html代码如下:
<div class="line">
<input type="text" name="birthday" id="showDatePicker" placeholder="请输入生日">
</div>