zou*_*ane 2 javascript jquery datepicker web
嘿家伙我想在我的网页上设置一个日期选择器,并禁用它的一些日期,所以它不能显示
这是代码:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link href="jquery-ui/jquery-ui.css" rel="stylesheet">
<script src="jquery-ui/external/jquery/jquery.js" ></script>
<script src="jquery-ui/jquery-ui.js"></script>
<script>
/** Days to be disabled as an array */
var disableddates = ["20-5-2015", "12-11-2014", "12-25-2014", "12-20-2014"];
function DisableSpecificDates(date) {
var m = date.getMonth();
var d = date.getDate();
var y = date.getFullYear();
// First convert the date in to the mm-dd-yyyy format
// Take note that we will increment the month count by 1
var currentdate = (m + 1) + '-' + d + '-' + y;
// We will now check if the date belongs to disableddates array
for (var i = 0; i < disableddates.length; i++) {
// Now check if the current date is in disabled dates array.
if ($.inArray(currentdate, disableddates) != -1) {
return [false];
}
}
}
$(function () {
$("#date").datepicker({
beforeShowDay: DisableSpecificDates
});
});
</script>
</head>
<body>
<input id="date" type="text">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但由于某种原因它不起作用...日期选择器甚至没有显示可以有人帮助
All*_*lez 17
试试这个,运行下面的代码.第一次我在当天添加0,以便它与比较中的格式匹配.
/** Days to be disabled as an array */
var disableddates = ["20-05-2015", "12-11-2014", "12-25-2014", "12-20-2014"];
function DisableSpecificDates(date) {
var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
return [disableddates.indexOf(string) == -1];
}
/*
var m = date.getMonth();
var d = date.getDate();
var y = date.getFullYear();
// First convert the date in to the mm-dd-yyyy format
// Take note that we will increment the month count by 1
var currentdate = (m + 1) + '-' + d + '-' + y ;
// We will now check if the date belongs to disableddates array
for (var i = 0; i < disableddates.length; i++) {
// Now check if the current date is in disabled dates array.
if ($.inArray(currentdate, disableddates) != -1 ) {
return [false];
}
}
}*/
$(function() {
$("#date").datepicker({
beforeShowDay: DisableSpecificDates
});
});Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link href="http://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
</head>
<body>
<input id="date" type="text">
</body>
</html>Run Code Online (Sandbox Code Playgroud)