admin管理员组文章数量:1201647
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=".8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src=".6.2/jquery.min.js"></script>
<script src=".8/jquery-ui.min.js"></script>
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>
Share
Improve this question
asked Jul 3, 2015 at 8:29
bobbob
2352 gold badges3 silver badges12 bronze badges
2 Answers
Reset to default 13You need to use the setDate
function of the datepicker
library. Try this:
$('#datepicker').datepicker('setDate', new Date()); // = set to today
As this is the first post that pops up when you search for how to set date in a datepicker, here's an answer for everyone that comes here trying to figure out how to do it with vanilla JS:
const date = document.getElementById('datepicker');
date.value = new Date().toISOString().split('T')[0].slice(0, 10);
<input id="datepicker" name="date" class="mydatepicker" />
本文标签: javascriptSet value of datepickerStack Overflow
版权声明:本文标题:javascript - Set value of datepicker? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738550853a2097338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论