问题
The default date for jQuery's datepicker is the current date, but I need it to be the pre-populated date from my #start_date
input field.
This is where I'm at now but it doesn't work.
var start_date = $('#start_date').val();
$('.datepicker').datepicker("option", "defaultDate", start_date);
<input type="text" id="start_date" name="start_date" class="datepicker form-control col-sm-6" placeholder="Start" value="<?php (!empty($row['start_date'])?$row['start_date']:'');?>>
回答1:
if the input field date is the same format which set in the input field when you pick the date, then it will be loaded by Datepicker by default without any javascript code just Datepicker intalization.
may be your variable $row['start_date'] show date and time in input field try to make the value in the format of mm/dd/yyyy and it should work perfectly.
回答2:
try:
var start_date = $('#start_date').val();
$('.datepicker').datepicker("option", "defaultDate", new Date(start_date));
来源:https://stackoverflow.com/questions/29808324/text-input-field-as-jquery-datepicker-default-date