gpt4 book ai didi

javascript - 使用变量修改日期选择器中的 maxDate 和 minDate

转载 作者:行者123 更新时间:2023-12-01 00:56:35 24 4
gpt4 key购买 nike

我使用此处找到的基本模板构建了一个日期选择器:

https://github.com/qodesmith/datepicker/blob/master/README.md

我的代码是:

const picker = datepicker(document.querySelector('#datepicker'), {



// Event callbacks.
onSelect: function(instance) {

var instanceSplit = instance.dateSelected.toString().split(" " ,4)
var instanceClean = instanceSplit.toString().replace(/,/g, ' ')
selectedDate = instanceClean
console.log(selectedDate)
update()

},


onShow: function(instance) {
console.log('Calendar showing.');
},
onHide: function(instance) {
console.log('Calendar hidden.');
},
onMonthChange: function(instance) {
// Show the month of the selected date.
},



// Customizations.
formatter: function(el, date, instance) {
// This will display the date as `1/1/2019`.
el.value = date.toDateString();
},

position: 'tr', // Top right.
startDay: 1, // Calendar week starts on a Monday.
customDays: ['S', 'M', 'T', 'W', 'Th', 'F', 'S'],
customMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
overlayButton: 'Go!',
overlayPlaceholder: 'Enter a 4-digit year',

// Settings.
alwaysShow: true, // Never hide the calendar.
dateSelected: new Date(), // Today is selected.
maxDate: new Date(2019, 5, 21), // Jan 1st, 2099.
minDate: new Date(2016, 5, 1), // June 1st, 2016.
startDate: new Date(), // This month.

});

虽然一切正常,但我想将 maxDate 设置为从今天算起的一周。虽然我知道我可以做这样的事情:

    var firstDay = new Date();
var nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);

我不知道如何将变量传递到 maxDate: 对象中。如果我在格式化程序函数中或全局声明 maxDate 变量,我无法将其传递到对象中。

事实上,我无法真正弄清楚下面的整个代码是如何工作的。我不确定格式化程序函数在做什么,也不清楚最后的对象如何与整个函数相关。对于这个有点普遍的问题表示歉意,但我发现日期选择器文档令人困惑。

最佳答案

您可以尝试内联 +7 天计算。

maxDate: new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000),

关于javascript - 使用变量修改日期选择器中的 maxDate 和 minDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56535624/

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