问题
I've explored maybe 30 threads and my problem still isn't solved.
I have a JQuery datepicker:
<input id="datepicker" name="date" class="mydatepicker" onchange="isValidDate()"></input>
I simply want to write a javascript function that accomplishes this when called:
<script type="text/javascript">
document.getElementById("datepicker").value = 'certain date';
</script>
datepicker is tied to these files:
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
回答1:
You need to use the setDate
function of the datepicker
library. Try this:
$('#datepicker').datepicker('setDate', new Date()); // = set to today
来源:https://stackoverflow.com/questions/31202132/set-value-of-datepicker