jquery – datepicker错误=未捕获的TypeError:无法读取未定义的属性“0”

无法获取jQueryUI datepicker选项在beforeShowDay之前工作.

我尝试了不同的帮助主题,但是我找不到它.

我收到这个错误

Uncaught TypeError: Cannot read property ‘0’ of undefined

这是我的JS.但它似乎不起作用

<script type="text/javascript">
jQuery(document).ready(function () {
    var your_dates = [new Date(13,5,5),new Date(13,10)];
    jQuery("div#event-calender").datepicker({
        beforeShowDay: function (date) {
            if (jQuery.inArray(date.toString(),your_dates) != -1) {
                return [true,'highlight'];
            }
        }
    });
});
</script>

解决方法

您需要始终返回一个数组,而不仅仅是条件匹配时.

documentation

beforeShowDay

Type: Function( Date date )

A function that takes a date as a parameter and must return an array

jQuery(document).ready(function () {
    var your_dates = [new Date(13,10)];
    jQuery("div#event-calender").datepicker({
        beforeShowDay: function (date) {
            var arr;
            if (jQuery.inArray(date.toString(),your_dates) != -1) {
                arr = [true,'highlight'];
            }else {
                arr = [true,''];
            }
            return arr;
        }
    });
});

FIDDLE

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...