发布网友 发布时间:2022-04-24 16:07
共1个回答
热心网友 时间:2022-04-22 04:01
bootstrap datetimepicker添加秒钟选择下拉框步骤
1)添加下拉框,找到this.picker.find('.datetimepicker-minutes td').html(html.join(''))这句,大概在709行附近,改为下面的
-收缩JavaScript代码
//添加datetimepicker下拉框,如果配置要选择秒,否则不添加
var addSec = /,s{1,2},/.test(',' + this.format.parts.join(',') + ','), sSec = addSec ? '<select style="width:100%">' : '';
this.addSec = addSec;
if (addSec) {
var orgSec = this.viewDate.getSeconds();
for (var _i = 0; _i < 60; _i++) sSec += '<option value="' + _i + '"' + (_i == orgSec ? ' selected' : '') + '>' + (_i < 10 ? '0' : '') + _i + '</option>';
sSec += '</select>';
}
this.picker.find('.datetimepicker-minutes td').html(html.join('') + sSec);
2)修改容器点击事件。大概846行,增加下面的红色语句,防止选择select秒钟时日期弹出框隐藏
-收缩JavaScript代码
click: function (e) {
e.stopPropagation();
e.preventDefault();
///防止选择秒钟选择器日期控件层隐藏
if (e.target.tagName == 'SELECT' || e.target.tagName == 'OPTION') return;
3)然后继续往下找到case 'span'语句,大概916,修改里面秒钟获取方式,如下所示
-收缩JavaScript代码
case 'span':
if (!target.is('.disabled')) {
var year = this.viewDate.getUTCFullYear(),
month = this.viewDate.getUTCMonth(),
day = this.viewDate.getUTCDate(),
hours = this.viewDate.getUTCHours(),
minutes = this.viewDate.getUTCMinutes(),
//修改datetimepicker秒钟获取方式
seconds = this.addSec ? this.picker.find('select').val() : this.viewDate.getUTCSeconds();
到此完成bootstrap datetimepicker添加秒钟选择下拉框功能。点击这里下载修改过的bootstrap-datetimepicker.js文件
注意:一定要配置format显示秒钟才会显示秒钟下拉框,否则不显示
-收缩JavaScript代码
$('.form_datetime').datetimepicker({
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 1,
format: 'yyyy-mm-dd hh:ii:ss'///
});