javascript - 使用同一页面上另一个日历中的日期更改 Bootstrap 日期选择器日历中的日期?

标签 javascript html twitter-bootstrap datepicker calendar

我的页面上有两个基本的 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/

相关文章:

javascript - 递归求和 JavaScript 多维数组

javascript - React-Native,闭包变量导致操作失败

javascript - 如何设置 Bootstrap Select 插件的工具提示?

css - Bootstrap 4 自定义构建生成器/下载

javascript - 使用 focusOut jquery 定位多个字段

javascript - Jquery .css 不工作

css - 在 HTML 和 CSS 中使用不同的布局

html - 在 Star Rater 无序列表旁边使用 CSS 在悬停时显示消息

javascript - TinyMCE,允许数据属性

html - Bootstrap 菜单调整大小错误