admin管理员组文章数量:1416051
I have a button which sets the datepicker to tomorrow using the following code:
$("#txtDateOfJourney").datepicker({ startDate: '+1d'});
But it's not working.
Here's a demo in fiddle
Any Ideas?
I have a button which sets the datepicker to tomorrow using the following code:
$("#txtDateOfJourney").datepicker({ startDate: '+1d'});
But it's not working.
Here's a demo in fiddle
Any Ideas?
Share Improve this question edited Mar 18, 2015 at 14:16 KyleMit♦ 30.9k72 gold badges511 silver badges702 bronze badges asked Mar 18, 2015 at 12:16 David RDavid R 15.7k8 gold badges59 silver badges74 bronze badges1 Answer
Reset to default 6You only pass in the options (as in datepicker({ startDate: '+1d'})
) when you're initializing the controller. Since it's already initialized you don't need to do that. Instead you want to use the setDate()
method and then pass in the javascript date representation of tomorrow a string representing the relative date like this:
$('#txtDateOfJourney').datepicker('setDate', "+1d");
Demo in Stack Snippets
$('#btnTomorrow').click(function() {
$('#txtDateOfJourney').datepicker('setDate', "+1d");
});
<link href="//cdnjs.cloudflare./ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare./ajax/libs/bootstrap-datepicker/1.4.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare./ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare./ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare./ajax/libs/bootstrap-datepicker/1.4.0/js/bootstrap-datepicker.js"></script>
<input type="text" id="txtDateOfJourney" class="datepicker" />
<button type="button" id="btnTomorrow" class="btn btn-info">Tomorrow</button>
本文标签: javascriptBootstrap DatePickerSetting the date to TomorrowStack Overflow
版权声明:本文标题:javascript - Bootstrap DatePicker - Setting the date to Tomorrow - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745248129a2649655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论