javascript - 获取日期选择器中选择的所有日期

标签 javascript jquery date datepicker

我正在使用 KelvinLuck 中的 jQuery 日期选择器插件。该日期选择器是一个多选日期选择器。在教程中,它展示了如何将所选日期显示到控制台。本教程一次仅显示一个日期。我想显示选择日期时选择的所有日期。因此从技术上讲是一组选定的日期。有没有办法做到这一点?这是 jsFiddle

HTML

<div class="date-pick"></div>

JS

$(function() {
  $('.date-pick')
    .datePicker({
      createButton: false,
      displayClose: true,
      closeOnSelect: false,
      selectMultiple: true,
      inline: true,
    })
    .bind(
      'click',
      function() {
        $(this).dpDisplay();
        this.blur();
        return false;
      }
    )
    .bind(
      'dateSelected',
      function(e, selectedDate, $td, state) {
        console.log('You ' + (state ? '' : 'un') // wrap
          + 'selected ' + selectedDate);

      }
    )
    .bind(
      'dpClosed',
      function(e, selectedDates) {
        console.log('You closed the date picker and the ' // wrap
          + 'currently selected dates are:');
        console.log(selectedDates);
      }
    );
});

最佳答案

来自documentation :

dpGetSelected( ) returns Array
Gets a list of Dates currently selected by this datePicker. This will be an empty array if no dates are currently selected or NULL if there is no datePicker associated with the matched element.

Example:
Will alert an empty array (as nothing is selected yet)

$('.date-picker').datePicker();
alert($('.date-picker').dpGetSelected());

关于javascript - 获取日期选择器中选择的所有日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45554544/

相关文章:

javascript - 如何有效地将 Immutable.js 映射列表转换为纯 js 对象数组以在 React 组件中使用?

用于 js 计算器的具有多个运算符的字符串的 Javascript 总数学

javascript - 用JS修改链接标题

java - 在java中格式化日期的问题

iphone - 设置特定日期的任务(iOS 应用程序)

javascript - 奇怪的 JavaScript 语句,它是什么意思?

javascript - AngularJS 中的计时器未绑定(bind) DOM 值

Javascript - 根据属性值从列表中获取特定对象

javascript - Bootstrap 3 进度条在转换完成时设置文本

mysql - 查询以查看订阅是否在两个日期范围内有效