开发者

error when calling date.getMonths()

开发者 https://www.devze.com 2023-02-12 05:50 出处:网络
this page offered sample code that would be ideal for a task I\'m working on Datepicker for web page that can allow only specific dates to be clicked

this page offered sample code that would be ideal for a task I'm working on

Datepicker for web page that can allow only specific dates to be clicked

however, when I implement it, I get the following error: TypeError: Result of expression 'date.getMonths' [undefined] is not a function.

I'm testing using the same versions of jquery (1.4.4) and jquery ui on jquery ui's official site any help is greatly appreciated!

<!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开发者_如何学C.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>


That would be because it's .getMonth, singular.


Most likely a typo.

use date.getMonth()

0

精彩评论

暂无评论...
验证码 换一张
取 消