gpt4 book ai didi

javascript - 如何将函数合并到函数中

转载 作者:行者123 更新时间:2023-11-28 16:19:52 25 4
gpt4 key购买 nike

我使用新日期创建的字符串日期更新了代码,并将其添加回 if 语句中。但这并没有禁用字符串或范围。我也添加了日期选择器代码。

function unavailableDays(date) {

function createDateRange(first, last) {
var dates = [];
for(var j = first; j < last; j.setDate(j.getDate() + 7)) {
dates.push(new Date(j.getTime()));
}
var alwaysDisabled = [new Date("1963-3-10T00:00:00"), new Date("1963-3-17T00:00:00"), new Date("1963-3-24T00:00:00"), new Date("1963-3-31T00:00:00"), new Date("1965-9-18T00:00:00")];
return dates.concat(alwaysDisabled);
}

var disabledDays = createDateRange(new Date("1978-8-10T00:00:00"), new Date("1978-11-5T00:00:00"));

var yy = date.getFullYear(), mm = date.getMonth(), dd = date.getDate();
for (i = 0; i < disabledDays.length; i++) {
if($.inArray(yy + '-' + (mm+1) + '-' + dd,disabledDays) != -1 || new Date() < date) {
return [false];
}
}
return [true];
}

$(document).ready(function (){
$('.selector').datepicker({
inline: true,
dateFormat: 'yy-mm-dd',
constrainInput: true,
changeYear: true,
changeMonth: true,
minDate: new Date(1940, 1-1, 1),
maxDate: new Date(2011, 10-1, 24),
beforeShowDay: unavailableDays,
onSelect: function(dateText, inst) {
$("#img").attr("src", "http://www.example.com" + dateText + ".jpg");
var chosenDates = $.datepicker.parseDate('yy-mm-dd', dateText);
var backToString = $.datepicker.formatDate('MM dd' + ',' + ' yy', chosenDates);
$('.info').html('You are viewing:' + '<br />' +
backToString).addClass('background');
}
});

});

最佳答案

在您的函数中,dates.push 需要是 date.push

关于javascript - 如何将函数合并到函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10068077/

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