admin管理员组

文章数量:1279114

  1. I need to set the "start date" to +1 day from the current day.
  2. And +3 days from the "start date" for the "end day"
  3. (optional) Highlight the trailing days

Fiddle can be found here:

Thanks!

  1. I need to set the "start date" to +1 day from the current day.
  2. And +3 days from the "start date" for the "end day"
  3. (optional) Highlight the trailing days

Fiddle can be found here: http://jsbin./icuduv/1

Thanks!

Share Improve this question asked Oct 16, 2012 at 13:03 Pennf0lioPennf0lio 3,8948 gold badges48 silver badges73 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

well you can simply do it like this

var d = new Date(); d.setDate( d.getDate() + 1 );
$('#txtStartDate').datepicker('setDate', d); 
d = new Date(); d.setDate( d.getDate() + 4 );
$('#txtEndDate').datepicker('setDate', d);

i have updated your demo as well have a look Here

for highlighting dates you can use the beforeShowDay event. It will get called for each date that needs to be shown in the calendar.

Get the date values using something along these lines:

var startDate = new Date();
var endDate = new Date();
startDate.setDate(today.getDate()+1);
endDate.setDate(startDate.getDate()+3);

$("#startDateInput").val(startDate.toString('MM/dd/yyyy'));
$("#endDateInput").val(endDate.toString('MM/dd/yyyy'));

This question could help with the highlighting:

Highlight dates in specific range with jQuery's datepicker

Maybe you can try this one

$(function() {
  var $defaultDate = new Date(); 
  $defaultDate.setDate( $defaultDate.getDate() + 1 );
  $('#txtStartDate').datepicker({defaultDate:   $defaultDate}).val(($defaultDate.getMonth()+1) + '/' + $defaultDate.getDate() + '/' +  $defaultDate.getFullYear()); 
  $defaultDate.setDate( $defaultDate.getDate() + 3 );
  $('#txtEndDate').datepicker({defaultDate: $defaultDate}).val(($defaultDate.getMonth()+1) + '/' + $defaultDate.getDate() + '/' +   $defaultDate.getFullYear()); 
});

本文标签: javascriptHow to set date range in jQuery Datepicker and set it as a default valueStack Overflow