bootstrap Datepicker : set value as last day of the month not working

℡╲_俬逩灬. 提交于 2019-12-13 07:42:25

问题


I have a bootstrap datepicker on months mode. I need the value to be last day of the month. How do I make this code work?

  $("#end-date").datepicker({
            minViewMode: 1,

    }).on('changeMonth',function(e)
        {                               
            //value of the end month is the last day of month       
            alert( new Date(e.date.getYear(), e.date.getMonth() + 1, 0));
              $("#end-date-catalog").datepicker('update', new Date(e.date.getYear(), e.date.getMonth() + 1, 0));
        });

plugin demo (here) jsfiddle (here)


回答1:


You don't have to change the source code for this to work. Just change the 'changeMonth' event to 'changeDate' event in your code. Also e.date.getYear() was returning 116 instead of 2016. That should be changed to e.date.getFullYear(). I will repost your code with my changes. Thanks a bunch because this helped me out!

$("#end-date").datepicker({
        minViewMode: 1,

}).on('changeDate',function(e)
    {                               
        //value of the end month is the last day of month       
        alert( new Date(e.date.getFullYear(), e.date.getMonth() + 1, 0));
          $("#end-date-catalog").datepicker('update', new Date(e.date.getFullYear(), e.date.getMonth() + 1, 0));
    });

For reference, here is a link to the docs, which is where I saw the difference between changeDate and changeMonth: https://bootstrap-datepicker.readthedocs.io/en/latest/events.html#changedate




回答2:


I went into the js source code of the datePicker and I solved it by putting the trigger(changeMonth) after setting the value .



来源:https://stackoverflow.com/questions/27840100/bootstrap-datepicker-set-value-as-last-day-of-the-month-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!