Set value of datepicker?

旧城冷巷雨未停 提交于 2019-12-10 14:11:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!