bootstrap-datepicker事件onchange不更新enddatepicker startDate:第二次的值

时间:2016-12-26 11:05:19

标签: javascript bootstrap-datepicker

"use strict";
let nowDate = new Date();
let today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);
let enddate;

 $('#startdatepicker').datepicker({
      autoclose:true,
      todayHighlight: true,
      startDate:today
    }).on("changeDate",function(e){

        let present=new Date(e.date);
        enddate = new Date(present.getFullYear(), present.getMonth(), present.getDate(), 0, 0, 0, 0);


        $('#enddatepicker').datepicker({
         autoclose: true,
         startDate: enddate
        });

    });

1 个答案:

答案 0 :(得分:0)

将更改更改为'更改' ,并且您的日期不是来自事件变量,您需要手动获取他'像这样:

    "use strict";
let nowDate = new Date();
let today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);
let enddate;

 $('#startdatepicker').datepicker({
      autoclose:true,
      todayHighlight: true,
      startDate:today
    }).on("change",function(e){

    var fromDate = $('#startdatepicker').val().split("/");
    let present=new Date(fromDate[2] , fromDate[1] - 1 , fromDate[0]);
    enddate = new Date(present.getFullYear(), present.getMonth(), present.getDate() + 1, 0, 0, 0, 0);
    alert(enddate);

        $('#enddatepicker').datepicker('setStartDate', enddate );
        });