问题
I'm using this jQuery inline datePicker plugin sample but I don't know how to set up default date selected. Do you have any idea?
回答1:
$('.date-pick').datePicker({
defaultDate: $.datepicker.parseDate("d m y", "31 8 2009")
})
回答2:
You will need to use the dpSetSelected method . I've added that into the code from the example page below:
$(function()
{
$('.turn-me-into-datepicker')
.datePicker({inline:true})
.dpSetSelected('01/04/2010') // The string should be in Date.format
.bind(
'dateSelected',
function(e, selectedDate, $td)
{
console.log('You selected ' + selectedDate);
}
);
});
As mentioned, if you have changed Date.format then you will need to ensure that the string is in the format you changed it to.
回答3:
Here: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerDefaultToday.html
$(function() {
var date = new Date(); // replace with your date
$('.date-pick').datePicker().val(date.asString()).trigger('change');
});
OR
Set date in your field:
<input class="date-pick" type="text" value="1/1/2009" />
回答4:
You can simply set value of that input box like $('#date-picker').val('22 Jun 2015');
回答5:
$("selector").datepicker('setDate', 'today');
To set UI widget and 'input' element.
来源:https://stackoverflow.com/questions/718599/how-to-setup-default-date-for-jquery-inline-datepicker