gpt4 book ai didi

javascript - Datepicker onSelect 格式化新的日期范围

转载 作者:行者123 更新时间:2023-11-28 08:14:17 24 4
gpt4 key购买 nike

我有 2 个日期选择器,一个是 fromDate,一个是 toDate。我可以在 beforeShowDay() 中成功突出显示从 fromDate 到 toDate 的范围,但我需要它在选择新值时突出显示。这会触发 onSelect 语句。有没有办法:

1) 再次触发 beforeShowDay?或

2) 获取新范围内的所有日期并对它们应用 css 类?

 beforeShowDay: function(date){
if (date >= initialFromDate && date <= initialToDate) {
return [true, 'ui-individual-date', ''];
}
else {
return [true, '', ''];
}
},
onSelect: function (dateText, obj) {

var fromDate = new Date(dateText);
var toDate = $(".dateDiv2").datepicker('getDate');

**get individual dates?
if (individualdate >= fromDate && individualDate <= toDate)
apply css class or formatting to individualDate**

},

The picture gives the generated css and html for the datepicker

enter image description here

enter image description here

最佳答案

我已经成功地使用了一个日期选择器作为起始日期,一个日期选择器作为一个日期选择器,所以我为一个日期选择器修改了它。这是代码:

 $(function () {
var today = new Date();
var thisYear = (today).getFullYear();
var fromDate = '1/1/2000' //this is the initial from date to set the datepicker range
var toDate = '1/7/2000' // this is the initial to date to set the datepicker range

//... initialize datepicker....
},
beforeShowDay: function(date){
//if the date is in range
if (date >= fromDate && date <= toDate) {
return [true, 'ui-individual-date', '']; //applies a css class to the range
}
else {
return [true, '', ''];
}
},
onSelect: function (dateText, obj) {

//sets the new range to be loaded on refresh call, assumes last click is the toDate
fromDate = toDate;
toDate = new Date(dateText);

$(".classDp1").datepicker("refresh");
$(".classDp2").datepicker("refresh");
},

每次刷新时,都会使用新的 fromDate 和 toDate 范围调用 beforeShowDay 函数。将变量放在函数外部并在函数内部修改它们可以使 css 的突出显示应用于每次单击。

关于javascript - Datepicker onSelect 格式化新的日期范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29085489/

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