【问题标题】:bootstrap Datepicker : set value as last day of the month not workingbootstrap Datepicker:将值设置为当月的最后一天不起作用
【发布时间】:2015-01-08 12:24:43
【问题描述】:

我在月份模式下有一个引导日期选择器。我需要该值是本月的最后一天。 如何使这段代码工作?

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

插件演示 (here) jsfiddle (here)

【问题讨论】:

  • 链接到插件页面?
  • 我用信息更新了我的问题

标签: jquery bootstrap-datepicker


【解决方案1】:

您无需更改源代码即可使用。只需在您的代码中将“changeMonth”事件更改为“changeDate”事件。 e.date.getYear() 也返回 116 而不是 2016。这应该更改为 e.date.getFullYear()。 我将用我的更改重新发布您的代码。非常感谢,因为这帮助了我!

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

作为参考,这里是文档的链接,我在这里看到了 changeDate 和 changeMonth 之间的区别:https://bootstrap-datepicker.readthedocs.io/en/latest/events.html#changedate

【讨论】:

    【解决方案2】:

    我进入了datePicker的js源代码,我通过在设置值之后放置触发器(changeMonth)来解决它。

    【讨论】:

      猜你喜欢
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多