我的页面上有两个基本的 Bootstrap 日期选择器日历。我试图了解如何使用changeDate 事件根据我在1 号日历上选择的日期来设置2 号日历的日期。我想将日期设置在第一个日历月之前三个月。
这是日历的 HTML:
<div class="profile-info-row">
<div class="profile-info-name"> Date of Birth *</div>
<div class="profile-info-value">
<div id="sandbox-container">
<span class="input-icon input-icon-right">
<input type="text" type="text" name="dob" id="dob" class="form-control">
<i class="ace-icon fa fa-calendar blue"></i>
</span>
</div>
</div>
</div>
这是日历的脚本:
<script type="text/javascript">
//datepicker plugin
$('#sandbox-container input').datepicker({
format: "dd-mm-yyyy",
todayBtn: "linked",
todayHighlight: true,
weekStart: 1,
autoclose: true
});
编辑:这个问题是关于 BOOTSTRAP 日期选择器,而不是 JQUERY 的。我认为这是大多数问题中常见的误解
最佳答案
//datepicker plugin
$('#sandbox-container input').datepicker({
format: "dd-mm-yyyy",
todayBtn: "linked",
todayHighlight: true,
weekStart: 1,
autoclose: true
}).on('changeDate', function(e) {
// `e` here contains the extra attributes
var newDate = new Date(e.date.setMonth(e.date.getMonth()+3));
$('#second-sandbox-container input').datepicker('setDate', newDate);
});
http://bootstrap-datepicker.readthedocs.org/en/latest/events.html#changedate
http://bootstrap-datepicker.readthedocs.org/en/latest/methods.html#setdate
关于javascript - 使用同一页面上另一个日历中的日期更改 Bootstrap 日期选择器日历中的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35895693/