此页面提供的示例代码非常适合我正在处理的任务
Datepicker for web page that can allow only specific dates to be clicked
然而,当我实现它时,我收到以下错误: TypeError:表达式'date.getMonths'[undefined]的结果不是函数。
我在jquery ui的官方网站上测试使用相同版本的jquery(1.4.4)和jquery ui 非常感谢任何帮助!
<!DOCTYPE html>
<html>
<head>
<base href="http://jqueryui.com/demos/datepicker/">
<title>TEST</title>
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
<script src="../../jquery-1.4.4.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
dates_allowed = {'2/26/2011': 1,'4/2/2011': 1};
$.datepicker.setDefaults({minDate: "+0"});
$.datepicker.setDefaults({maxDate: (new Date(2011, 3, 2))});
$('#Date').datepicker({
// called for every date before it is displayed
beforeShowDay: function(date) {
var date_str = [
date.getFullYear(),
date.getMonths() + 1,
date.getDay()
].join('-');
if (dates_allowed[date_str]) {
return [true, 'good_date', 'This date is selectable'];
} else {
return [false, 'bad_date', 'This date is NOT selectable'];
}
}
});
});
</script>
</head>
<body>
<input type="text" id="Date">
</body>
</html>