Bootstrap - datetimepicker add custom button like

2020-03-24 07:54发布

How to add custom button like Today in bootstrap datetimepicker?

For example: Week ago, Yesterday.

https://github.com/Eonasdan/bootstrap-datetimepicker

enter image description here

2条回答
forever°为你锁心
2楼-- · 2020-03-24 08:12

For now i found this solution:

        $('#route-from-date').datetimepicker({
            autoclose: true,
            language: 'pl'
        });
        $('#route-to-date').datetimepicker({
            autoclose: true,
            language: 'pl',
            //todayBtn: 'ok'
        });
        $('.datetimepicker tfoot').append('<tr><th colspan="7" class="today_">Dzisiaj</th></tr><tr><th colspan="7" class="yesterday">Wczoraj</th></tr><tr><th colspan="7" class=" week">Tydzień</th></tr>');
        $('.datetimepicker tfoot th').on('click',function(){
            var $th = $(this);
            var d = new Date();
            var fd,td;
            if($th.hasClass('yesterday')){
                d.setDate(d.getDate() - 1);
            }
            else if ($th.hasClass('week')){
                d.setDate(d.getDate() - 7);
                fd = d.getFullYear() + '-' + ((d.getMonth()<10)?  '0'+(d.getMonth()+1) : d.getMonth()+1  ) + '-' + ((d.getDate()<10)?  '0'+d.getDate() : d.getDate()  ) + ' 00:00';
                d.setDate(d.getDate() + 7);
                td = d.getFullYear() + '-' + ((d.getMonth()<10)?  '0'+(d.getMonth()+1) : d.getMonth()+1  ) + '-' + ((d.getDate()<10)?  '0'+d.getDate() : d.getDate()  ) + ' 23:59';
            }

            if(!$th.hasClass("week")){
                fd = d.getFullYear() + '-' + ((d.getMonth()<10)?  '0'+(d.getMonth()+1) : d.getMonth()+1  ) + '-' + ((d.getDate()<10)?  '0'+d.getDate() : d.getDate()  ) + ' 00:00';
                td = d.getFullYear() + '-' + ((d.getMonth()<10)?  '0'+(d.getMonth()+1) : d.getMonth()+1  ) + '-' + ((d.getDate()<10)?  '0'+d.getDate() : d.getDate()  ) + ' 23:59';
            }

            $('#route-from-date').val(fd).datetimepicker('update', fd);
            $('#route-to-date').val(td).datetimepicker('update', td);
            $('.datetimepicker').hide();
        });
查看更多
▲ chillily
3楼-- · 2020-03-24 08:24

You can do something like this:

$('#route-from-date').datetimepicker({
    autoclose: true,
    language: 'pl',
    showTodayButton: true
 });
 $('#route-to-date').datetimepicker({
    autoclose: true,
    language: 'pl',
    showTodayButton: true
 });

Documentation here

查看更多
登录 后发表回答