JQuery ui-date picker, wyłączanie określonych dat
Próbuję wyłączyć określone daty za pomocą interfejsu JQuery. Jednak nie mam szczęścia, oto mój kod: {]}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="development-bundle/themes/ui-lightness/jquery.ui.all.css">
<style type="text/css">
.ui-datepicker .preBooked_class { background:#111111; }
.ui-datepicker .preBooked_class span { color:#999999; }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jQuery UI Datepicker</title>
<script type="text/javascript" src="development-bundle/jquery-1.7.1.js"></script>
<script type="text/javascript" src="development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="development-bundle/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="development-bundle/ui/jquery.ui.datepicker.js"></script>
Instantiate datepicker object
<script type="text/javascript">
$(function() {
$( "#iDate" ).datepicker({
dateFormat: 'dd MM yy',
beforeShowDay: checkAvailability
});
})
Pobierz daty, które mają być wyłączone w kalendarzu
var unavailableDates = ["9-3-2012","14-3-2012","15-3-2012"];
function unavailable(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false,"","Unavailable"];
}
}
$('#iDate').datepicker({ beforeShowDay: unavailable });
</script>
</head>
<body>
<input id="iDate">
</body>
</html>
Wygląda na to, że to nie działa. zdrowie. 13
2 answers
Wygląda na to, że dzwonisz dwa razy na jednym wejściu. Trudno jest podążać za twoim kodem, ale jeśli go przeorganizujesz i usuniesz drugie wywołanie datepicker
, wszystko powinno działać:
<script type="text/javascript">
var unavailableDates = ["9-3-2012", "14-3-2012", "15-3-2012"];
function unavailable(date) {
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false, "", "Unavailable"];
}
}
$(function() {
$("#iDate").datepicker({
dateFormat: 'dd MM yy',
beforeShowDay: unavailable
});
});
</script>
Przykład: http://jsfiddle.net/daCrosby/JjPrU/334/
29
Author: Andrew Whitaker,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-27 08:11:47
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-27 08:11:47
Pomocna odpowiedź..Jeśli chcesz wyłączyć perticular dzień, można zrobić jak poniżej:
$scope.dateOptions = {
beforeShowDay: unavailable
};
function unavailable(date) {
if (date.getDay() === 0) {
return [true, ""];
} else {
return [false, "", "Unavailable"];
}
}
Powyższe włącza tylko niedzielę, a wszystkie pozostałe dni zostaną wyłączone. Mam nadzieję, że to pomoże.
0
Author: Deva,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-30 07:16:37
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-30 07:16:37