简体   繁体   English

获取在日期选择器中选择的所有日期

[英]Get all dates selected in date picker

I am using a jQuery datepicker plugin from KelvinLuck . 我正在使用KelvinLuck的jQuery datepicker插件。 This date picker is a multi-select date picker. 该日期选择器是多选日期选择器。 In the tutorial it shows how you can display the selected date to the console. 在本教程中,它显示了如何在控制台上显示所选日期。 The tutorial only shows one date at a time. 本教程一次只显示一个日期。 I'd like to display all the dates that are selected when a date is picked. 我想显示选择日期时选择的所有日期。 So technically an array of selected dates. 因此,从技术上讲,是一系列选定的日期。 Is there a way to do this? 有没有办法做到这一点? Here's a jsFiddle 这是一个jsFiddle

HTML 的HTML

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

JS 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);
      }
    );
});

From the documentation : 文档中

dpGetSelected( ) returns Array
Gets a list of Dates currently selected by this datePicker. 获取此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. 如果当前未选择任何日期,则此数组将为空;如果与匹配的元素没有关联的datePicker,则为NULL。

Example: 例:
Will alert an empty array (as nothing is selected yet) 将提醒一个空数组(因为尚未选择任何内容)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM