gpt4 book ai didi

javascript - 禁用 javascript 中的特定日期

转载 作者:搜寻专家 更新时间:2023-10-31 21:27:04 25 4
gpt4 key购买 nike

我有javascript函数

$(document).ready(function () {

var d = new Date();
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
today = monthNames[d.getMonth()] + ' ' + d.getDate() + ' ' + d.getFullYear();

$('#to').attr('disabled', 'disabled');
$('#from').datepicker({
defaultDate: "+1d",
beforeShowDay: DisableSpecificDates,
minDate: "+1d",
maxDate: "+3M",
dateFormat: 'dd.mm.yy',
showOtherMonths: true,
changeMonth: true,
selectOtherMonths: true,
required: true,
altField: '#checkin',
numberOfMonths: 1,
});

$('#from').change(function () {
var from = $('#from').datepicker('getDate');
var date_diff = Math.ceil((from.getTime() - Date.parse(today)) / 86400000);
var maxDate_d = date_diff+7+'m';
date_diff = date_diff + 1;
$('#to').val('').removeAttr('disabled').removeClass('hasDatepicker').datepicker({
dateFormat: 'dd.mm.yy',
minDate: date_diff,
maxDate: maxDate_d,
altField: '#checkout',
});
});

$('#to').keyup(function () {
$(this).val('');
alert('Please select date from Calendar');
});
$('#from').keyup(function () {
$('#from,#to').val('');
$('#to').attr('disabled', 'disabled');
alert('Please select date from Calendar');
});

这允许我在表单中创建 JavaScript 日期选择( checkin 和 checkout 日期)

功能完美,但这里需要集成一个额外的功能。

我想禁用特定日期从 - 到我找到这个 JavaScript 并想集成到上面的函数中。

     var dakavebuli = 1000*60*60*24;
boloshesvla = new Date('2015-12-24');
bologasvla = new Date("2015-12-25");
var shualeduritarigebi = (bologasvla.getTime()- boloshesvla.getTime())/dakavebuli;


for(var i=0;i<=shualeduritarigebi; i++)
{
var checking = boloshesvla.getTime()+dakavebuli*i;
var checkout = new Date(checking);

alert (checkout.getFullYear()+"-"+(checkout.getMonth()+1)+"-"+checkout.getDate());
}

最佳答案

您正在使用的函数不会向 datepicker 返回任何内容,因此不会阻止任何此类日期,您可以使用此函数:

这些是存储在要阻止的数组中的日期。

var $myBadDates = new Array("10 October 2010","21 November 2010","12 December 2010","13 January 2011","14 February 2011","15 March 2011");

函数定义:

function DisableSpecificDates(mydate){
var $return=true;
var $returnclass ="available";
$checkdate = $.datepicker.formatDate('dd MM yy', mydate);
for(var i = 0; i < $myBadDates.length; i++)
{
if($myBadDates[i] == $checkdate)
{
$return = false;
$returnclass= "unavailable";
}
}
return [$return,$returnclass];
}

关于javascript - 禁用 javascript 中的特定日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34461975/

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