如何获得相同的fromdate值到日历控件的todate

时间:2015-12-11 11:09:25

标签: jquery

这是我使用bootstrap日历控件的设计部分

 <div class="row">
                            @*From date Control*@
                            <div class="form-group col-lg-6" id="fromdate">

                                <label class="col-lg-3 control-label">From Date</label>
                                <div class="col-xs-9 dateContainer">
                                    <div class="input-group input-append date dateContainer" id="startDatePicker">
                                        <input type="text" class="form-control" id="startDate" name="startDate" placeholder="Select From Date" />
                                        <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>
                            </div>
                            @*To date Control*@
                            <div class="form-group col-lg-6" id="enddate">

                                <label class="col-lg-3 control-label">To Date</label>
                                <div class="col-xs-9 dateContainer">
                                    <div class="input-group input-append date dateContainer" id="endDatePicker">
                                        <input type="text" class="form-control" id="endDate" name="endDate" placeholder="Select To Date" />
                                        <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>
                            </div>
                        </div>

和我的jquery代码为:

$('#startDatePicker')
            .datepicker({
                format: 'dd-mm-yyyy',
            })

        .on('changeDate', function (e) {
            //debugger;
            var startdate = $("#startDate", this).val();
            $('input[name="endDate"]').val(startdate);

            // Revalidate the start date field
            $('#frmAddTurnover').formValidation('revalidateField', 'startDate');
        });

        $('#endDatePicker')
            .datepicker({
                format: 'dd-mm-yyyy',
            })
            .on('changeDate', function (e) {
                // Revalidate the end date field
                $('#frmAddTurnover').formValidation('revalidateField', 'endDate');
            });

在这里,我希望将fromdate值变为todate。 我希望fromdate的值与日历相同。

1 个答案:

答案 0 :(得分:0)

使用datepicker的setDate函数:

...
var startdate = $("#startDate", this).val();
$('input[name="endDate"]').datepicker("setDate",startdate);
...