问题
I am using the Bootstrap datepicker and the following is my jQuery code:
$('.form_date').datetimepicker({
language: 'en',
/* endDate: '+0d', */
startDate: '+1d',
weekStart: 1,
autoclose: 1,
startView: 2,
format: 'dd/mm/yyyy',
minView: 2,
forceParse: 0,
});
The following is what I get:
I want have the start date highlighting on tomorrow according to our requirement. I have found one option defaultViewDate on the Bootstrap datepicker documentation. (http://bootstrap-datepicker.readthedocs.org/en/latest/options.html)
It states that I have to set the year, month, and day key of defaultViewDate. But I don't know how to set it.
回答1:
Try following;
$('.form_date').datetimepicker({
defaultViewDate: { year: 1977, month: 04, day: 25 }
});
It should be in the format of Object with year, month and day keys. For more information please see here;
https://eternicode.github.io/bootstrap-datepicker
回答2:
Your format for the startDate option looks correct, but I do see some other errors in your JavaScript that may be confusing the DatePicker (and causing your startDate to be ignored):
- The
autocloseoption should be formatted as aBooleanand should be eithertrueorfalse. - The
minViewoption that you have defined should actually be:minViewMode. - The
forceParseoption should be formatted as aBooleanand should be eithertrueorfalse. - You have a trailing comma that follows your final option (
forceParse), which should be removed so that there is no comma after the final option.
If you correct the problems listed above, I believe you will begin to see a correct startDate.
来源:https://stackoverflow.com/questions/28322680/bootstrap-datepicker-changing-start-date-to-tomorrow