问题
i have this markup
<input tabindex="5" type="text" class="bgFecha date-pick" id="date2" value="12/03/2011" name="date2"/>
Please note the value of the input
but onclick the datepikcer starts with a 2 years later date:
This is the call:
$(function(){
$('.date-pick').attr('readonly','true');
$('.date-pick').datePicker({clickInput:true})
});
What is wrong? i need the datepicker to use the value="" date to start.
thanks
回答1:
The default format for jquery datepicker it's mm/dd/yy. You need to use 12/03/11.
Or you can change the date format:
$(function(){
$('.date-pick').attr('readonly','true');
$('.date-pick').datePicker({
clickInput:true,
altFormat: 'mm/dd/yyyy' // change the date format
});
});
回答2:
You can try set up date before you init the calendar like this
var today = new Date();
$('.date-pick').each(function(){
$(this).val(today.toString("mm/dd/yy"));
});
来源:https://stackoverflow.com/questions/7997484/datepicker-does-not-start-with-the-input-value