Bootstrap的 DatePicker 日期范围选择

$(function(){
  
    //开始
   $('.startdatepicker').datepicker({
        format: "yyyy-mm-dd",
        todayBtn:'linked',
        clearBtn:true,
        language: 'cn',
        autoclose:true,
        todayHighlight:true,
        startDate:'0',
   }).on('changeDate',function (ev) {
       if (ev.date){
          $('.enddatepicker').datepicker('setStartDate',new Date(ev.date.valueOf()))
       }else{
          $('.enddatepicker').datepicker('setStartDate',0)
       }
   });
   //结束
    $('.enddatepicker').datepicker({
        format: "yyyy-mm-dd",
        todayBtn:'linked',
        clearBtn:true,
        language: 'cn',
        autoclose:true,
        todayHighlight:true,
        startDate:'0',
    }).on('changeDate',function (ev) {
        if(ev.date){
           $('.startdatepicker').datepicker('setEndDate', new Date(ev.date.valueOf()))
        }else {
           $('.startdatepicker').datepicker('setEndDate',null)
        }

    });

});

laravel js 引入

{!! Theme::asset()->container('specific-css')->usePath()->add('datepicker-css', 'plugins/ace/css/datepicker.css') !!}
{!! Theme::asset()->container('specific-js')->usePath()->add('datepicker-js', 'plugins/ace/js/date-time/bootstrap-datepicker.min.js') !!}

留下评论