问题
After implementing datepicker, I am able to show Week picker using this. But in addition to this I even want to show the current week range on load.
When user clicks on any date, it shows the week range but how can I show current week range onload as well ?
For example, if user clicks on Nov 2 it shows the week range Nov 2 - Nov 8 but not showing the current week range which is Oct 26 - Nov 1 by default onload.
The below function shows the current week start and end date, but how can I show it on load without onselect.
var showCurrentWeek = function() {
var defaultStartDate = $('#startDate').text($.datepicker.formatDate( 'M d', startDate));
var defaultEndDate = $('#endDate').text($.datepicker.formatDate( 'M d', endDate));
alert(defaultStartDate.text());
alert(defaultEndDate.text());
}
How can I achieve this ?
Thanks.
回答1:
There are probably other ways to do this, but here's one. Simulate a click on the current date by adding this code:
$(function() {
......
$(".ui-datepicker-current-day").click();
}
来源:https://stackoverflow.com/questions/26686307/jquery-ui-datepicker-show-current-week-on-load