简体   繁体   中英

Get all dates selected in date picker

I am using a jQuery datepicker plugin from KelvinLuck . 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

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

From the 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()); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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