datepicker错误=未捕获的TypeError:无法读取未定义的属性“0” [英] datepicker Error = Uncaught TypeError: Cannot read property '0' of undefined
本文介绍了datepicker错误=未捕获的TypeError:无法读取未定义的属性“0”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法获取jQueryUI datepicker选项 beforeShowDay
工作。
Can't get jQueryUI datepicker option beforeShowDay
to work.
我尝试过不同的帮助主题已经发现但我无法正常工作。
I've tried different help topics I've found but I can't get it working.
我收到此错误
未捕获的TypeError:无法读取未定义的属性'0'
Uncaught TypeError: Cannot read property '0' of undefined
这是我的JS。但它似乎不起作用
This is my JS. but it doesn't seems to work
<script type="text/javascript">
jQuery(document).ready(function () {
var your_dates = [new Date(13, 5, 5), new Date(13, 5, 10)];
jQuery("div#event-calender").datepicker({
beforeShowDay: function (date) {
if (jQuery.inArray(date.toString(), your_dates) != -1) {
return [true, 'highlight'];
}
}
});
});
</script>
推荐答案
您需要始终返回数组,而不仅仅是条件匹配。
You need to always return an array, not just when a condition matches.
来自文档:
beforeShowDay
beforeShowDay
类型:功能(日期日期)
Type: Function( Date date )
将日期作为参数并且必须返回数组的函数
jQuery(document).ready(function () {
var your_dates = [new Date(13, 5, 5), new Date(13, 5, 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;
}
});
});
这篇关于datepicker错误=未捕获的TypeError:无法读取未定义的属性“0”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文