答案 0 :(得分:2)
这是一个workaround,感谢RomeroMsk。
CSS:
.datepicker-years .picker-switch {
cursor: default !important;
background: inherit !important;
}
JS:
$('#datetimepicker1').datetimepicker({
// your datetimepicker options go here, f.i.:
inline: true,
sideBySide: false,
format : "DD/MMM/YYYY",
maxDate : moment()
}).on('dp.show dp.update', function () {
$(".datepicker-years .picker-switch").removeAttr('title')
//.css('cursor', 'default') <-- this is not needed if the CSS above is used
//.css('background', 'inherit') <-- this is not needed if the CSS above is used
.on('click', function (e) {
e.stopPropagation();
});
});
答案 1 :(得分:1)
您也可以通过更改bootstrap-datetimepicker.js来实现这一点,这是最简单的方法。您所要做的就是在编辑器中打开bootstrap-datetimepicker.js -
查找并评论该行 -
yearsViewHeader.eq(1).attr('title', options.tooltips.selectDecade);
就在&#34; yearsView.find(&#39; .disabled&#39;)的行下面.removeClass(&#39; disabled&#39;); &#34;添加此行
yearsViewHeader.eq(1).addClass('disabled');
您可以在此link
找到更详细的步骤答案 2 :(得分:0)
经过多年努力为自己解决这个问题,我终于破解了它。
我已经调整了@Sarpe的答案,因此它可以在加载时禁用数十年的按钮。 Sarpe的解决方法要求用户在diabling之前点击日期。
$('#datetimepicker1').datetimepicker({
inline: true,
sideBySide: false,
format: 'YYYY-MM-DD',
maxDate: moment()
});
$(".datepicker-years .picker-switch").addClass('disable').on('click', function(e) {
e.stopPropagation();
});
.bootstrap-datetimepicker-widget .datepicker-years thead .picker-switch {
cursor: default !important;
background: inherit !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/eonasdan-bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
<div id="datetimepicker1"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/eonasdan-bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
答案 3 :(得分:0)
这是最好,最简单的解决方案。
.datepicker-dropdown .datepicker-years .datepicker-switch, .datepicker-dropdown .datepicker-months .datepicker-switch {
pointer-events: none;
}
答案 4 :(得分:0)
这对于使用Bootstrap Datepicker的我来说是有效的
$('#datetimepicker1').datepicker({
format: 'DD-MM-YYYY'
}).on('show', () => {
const decadesDiv = document.querySelector(".datepicker-decades");
if (decadesDiv) {
decadesDiv.firstElementChild.firstElementChild.childNodes.forEach((tr,idx)
=> {
if (idx === 0)
tr.style.visibility = "hidden";
else {
tr.children[1].addEventListener('click', (e) => {
e.stopPropagation() });
//tr.children[1].style.visibility = "hidden"; //optional CSS
}
});
}
});