나는 자바 스크립트 jquery 날짜 선택기를 가지고 있는데, 데이터베이스에서 일 수를 기준으로 일을 선택할 수있을뿐만 아니라 현재 날짜를 선택할 수 있습니다 휴일로 데이터베이스에 없습니다). 주말도 사용할 수 없습니다.php/javascript의 날짜 선택기에 관해서
지금 내가하려는 것은 사용자가 날짜 선택 도구에서 데이터베이스 +1에서 하루를 선택할 수 있도록 허용하는 것입니다.
필자는 데이터베이스에 입력 된 최신 날짜를 분명히 꺼 냈으므로 이번에는 선택할 수있는 날짜입니다.하지만 다음 날이 비활성화 된 경우에는 어떻게됩니까? 다른 휴일 날짜부터 요? 어떤 방법으로이 문제를 해결할 수 있습니까? 휴가 날짜에 조건이 있습니까?
내 자바 스크립트 JQuery와 날짜 선택 기압 :
<script type="text/javascript">
// Holiday Dates
var unavailableDates =
[<?php
while($date = mysqli_fetch_assoc($execute)) {
// Populating javascript array with the dates from database
echo '"' . $date = date('Y-n-j', strtotime($date['holiday_date'])) . '"';
// Adding a comma in array
if ($i < $number) {
echo ',';
}
$i ++;
}
?>
];
// Entered Dates
var unavailableEnteredDates =
[<?php
while($dateEntered = mysqli_fetch_assoc($executeQuery)) {
// Populating javascript array with the dates from database
echo '"' . $dateEntered = date('Y-n-j', strtotime($dateEntered['totalsDate'])) . '"';
// Adding a comma in array
if ($y < $number2) {
echo ',';
}
$y ++;
}
?>
];
// Concatenented array of 2 above
var allUnavailableDates = unavailableDates.concat(unavailableEnteredDates);
// Sets the no weekends and specified holiday dates
function noWeekendsOrHolidays(date) {
var noWeekend = jQuery.datepicker.noWeekends(date);
return noWeekend[0] ? holidays(date) : noWeekend;
}
// Gets the holidays
function holidays(date) {
dmy = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
if ($.inArray(dmy, allUnavailableDates) == -1) {
return [true, ""];
} else {
return [false, "", "Holiday Date"];
}
}
// Setting up the Date Picker
$(function() {
$("#datepickerUser").datepicker({
dateFormat: 'yy-m-d',
beforeShowDay: noWeekendsOrHolidays,
maxDate: "+0d"
});
$(function() { ("#testButton").datepicker("show") });
});
내가 생각 해낸 내 솔루션 :
// Adding one to the day so we can display this
$latestPlusOne = date('Y-n-j', strtotime("$latestDate + 1 day"));
$availableTakingDate;
// This for loop will loop through the size of the array
// Each time it finds the date inside the array it will plus 1 to the date
// Otherwise, break out of the loop and the new date var will be an available one
for ($i = 0; $i <= count($dateArray); $i++) {
if (in_array($latestPlusOne, $dateArray)) {
$latestPlusOne = date('Y-n-j', strtotime("$latestPlusOne + 1 day"));
} else {
$availableTakingDate = $latestPlusOne;
break;
}
}
?>
<script type="text/javascript">
// Date :: wanted available
var availableDate = <?php echo json_encode($availableTakingDate); ?>;
function displayDate(date) {
dmy = date.getFullYear() + "-" + (date.getMonth() +1) + "-" + date.getDate();
if (dmy == availableDate) {
return [true, ""];
} else {
return [false, ""];
}
}
// Setting up the Date Picker
$(function() {
$("#datepickerUser").datepicker({
dateFormat: 'yy-m-d',
beforeShowDay: displayDate,
maxDate: "+0d"
});
$(function() { ("#testButton").datepicker("show") });
});
사용자가 문제를 해결할 수 있도록 최소한의 코드를 붙여야합니다. – bitoiu
감사합니다. ive가 내 자바 스크립트를 추가했습니다. – MITSolutions