【问题标题】:Bootstrap - datetimepicker add custom button like TodayBootstrap - datetimepicker 添加自定义按钮,如 Today
【发布时间】:2015-06-18 08:45:13
【问题描述】:

如何在 bootstrap datetimepicker 中添加像 Today 这样的自定义按钮?

例如:一周前,昨天。

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

【问题讨论】:

    标签: javascript jquery html css twitter-bootstrap


    【解决方案1】:

    现在我找到了这个解决方案:

            $('#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();
            });
    

    【讨论】:

      【解决方案2】:

      你可以这样做:

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

      文档here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-16
        • 2012-04-16
        相关资源
        最近更新 更多