我已经在js文件中为我的网站的所有日期选择器定义了一个通用选项,现在我正在尝试通过id更新/覆盖特定字段,但我无法实现它。
**HTML**
<input id="mydate" class="datepick" type="text">
**JS**
$('.datepick').datepicker({
autoclose: true,
todayHighlight: true,
/* startDate: '+1m' This option will work here*/
});
$('#mydate').datepicker({
startDate: '+1m' /* But it doesnt work here*/
});
答案 0 :(得分:1)
您需要使用setStartDate
设置初始化datepicker后的开始日期
这是jsFiddle
$('.datepick').datepicker({
autoclose: true,
todayHighlight: true,
/* startDate: '+1m' This option will work here*/
});
$('#mydate').datepicker('setStartDate','+1m');
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/css/datepicker.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/js/bootstrap-datepicker.min.js"></script>
<input id="mydate" class="datepick" type="text">