这个插件还是比较简单的,而且样式也比较漂亮,可以自定义选择年月日、年月日时分、年月、时间段选择等等。
bootstrap.min.css
或bootstrap.css
bootstrap-datepicker.min.css
或bootstrap-datepicker.min.css
jquery.min.js
或jquery.js
bootstrap-datepicker.min.js
或bootstrap-datepicker.js
bootstrap-datepicker.zh-CN.js
其中第五个表示将插件换成中文显示
<div class="container">
<h1 class="text-center text-info">Datepicker日期选择器插件</h1>
<!-- 年月日 -->
<div class="form-group has-success">
<label class="control-label" for="ymd">年月日
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-time"></span>
<input type="text" class="form-control" id="ymd" aria-describedby="inputGroupSuccess1Status">
</div>
</label>
</div>
<!-- 年月日时分 -->
<div class="form-group has-warning">
<label class="control-label" for="ymdhm">年月日时分
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-time"></span>
<input type="text" class="form-control" id="ymdhm" aria-describedby="inputGroupSuccess1Status">
</div>
</label>
</div>
<table class="table">
<thead>
<tr>
<th>
<div class="form-group has-error">
<label class="control-label" for="start">开始时间
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-time"></span>
<input type="text" class="form-control" id="start">
</div>
</label>
</div>
</th>
<th>
<div class="form-group has-error">
<label class="control-label" for="end">结束时间
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-time"></span>
<input type="text" class="form-control" id="end">
</div>
</label>
</div>
</th>
</tr>
</thead>
</table>
</div>
<script>
$('#ymd').fdatepicker({
format: 'yyyy-mm-dd',
language: "zh-CN"
});
$('#ymdhm').fdatepicker({
language: "zh-CN",
format: 'yyyy-mm-dd hh:ii',
pickTime: true
});
var nowTemp = new Date(0, 0, 0, 0, 0, 0);
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var checkin = $('#start').fdatepicker({
language: "zh-CN",
format: 'yyyy-mm-dd',
onRender: function(date) {
return date.valueOf() < now.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function(ev) {
if (ev.date.valueOf() > checkout.date.valueOf()) {
var newDate = new Date(ev.date)
newDate.setDate(newDate.getDate() + 1);
checkout.update(newDate);
}
checkin.hide();
$('#end')[0].focus();
}).data('datepicker');
var checkout = $('#end').fdatepicker({
language: "zh-CN",
format: 'yyyy-mm-dd',
onRender: function(date) {
return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function(ev) {
checkout.hide();
}).data('datepicker');
</script>
我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1pk0f70ievu1e