gpt4 book ai didi

jquery - daterangepicker 两个不同的输入

转载 作者:行者123 更新时间:2023-12-01 02:40:24 29 4
gpt4 key购买 nike

我有两个相同形式的不同日期范围选择器,因为我需要将它放在两个输入中,而不仅仅是一个输入中。所以我使用类选择器对其进行初始化:$('.daterange').daterangepicker({});

一切都很完美,但我想同时改变两个。如果我在第一个范围中选择一个范围,当我打开第二个范围时,我希望在日历中选择相同的范围。所以我尝试在 ON SHOW 事件中做到这一点

$('.daterange').daterangepicker()
.on('apply.daterangepicker' ,function(ev, picker) {
$('.scheduledStartGmt').val(picker.startDate.format(picker.format)).change();
$('.scheduledEndGmt').val(picker.endDate.format(picker.format)).change();
})
.on('show.daterangepicker' ,function(ev, picker){

$('.daterange').data('daterangepicker').setStartDate($('.scheduledStartGmt').val());
$('.daterange').data('daterangepicker').setEndDate($('.scheduledEndGmt').val());

});

仅更改第一个。我该怎么做?

最佳答案

我遇到了同样的问题,但找到了解决方案,这可能对您有帮助:

看看我的代码:

    if($('#search_checkin, #search_checkout').length){
// check if element is available to bind ITS ONLY ON HOMEPAGE
var currentDate = moment().format("DD-MM-YYYY");

$('#search_checkin, #search_checkout').daterangepicker({
locale: {
format: 'DD-MM-YYYY'
},
"alwaysShowCalendars": true,
"minDate": currentDate,
"maxDate": moment().add('months', 1),
autoApply: true,
autoUpdateInput: false
}, function(start, end, label) {
// console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
// Lets update the fields manually this event fires on selection of range
var selectedStartDate = start.format('DD-MM-YYYY'); // selected start
var selectedEndDate = end.format('DD-MM-YYYY'); // selected end

$checkinInput = $('#search_checkin');
$checkoutInput = $('#search_checkout');

// Updating Fields with selected dates
$checkinInput.val(selectedStartDate);
$checkoutInput.val(selectedEndDate);

// Setting the Selection of dates on calender on CHECKOUT FIELD (To get this it must be binded by Ids not Calss)
var checkOutPicker = $checkoutInput.data('daterangepicker');
checkOutPicker.setStartDate(selectedStartDate);
checkOutPicker.setEndDate(selectedEndDate);

// Setting the Selection of dates on calender on CHECKIN FIELD (To get this it must be binded by Ids not Calss)
var checkInPicker = $checkinInput.data('daterangepicker');
checkInPicker.setStartDate(selectedStartDate);
checkInPicker.setEndDate(selectedEndDate);

});

} // End Daterange Picker

如果您需要我解释,请告诉我。

关于jquery - daterangepicker 两个不同的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46358075/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com