jQuery Datepicker 仅显示星期一并禁用某些星期一
我在尝试组合仅显示星期一以及禁用 jQuery 日期选择器的 beforeShowDay 参数上的特定日期时遇到麻烦...我希望用户只能选择星期一,除了 2/20/2012 和 2/ 27/2012 但我不知道如何实现这个......
<script type="text/javascript">
var unavailableDates = ["20-02-2012", "27-12-2012"];
function unavailable(date) {
dmy = (date.getDay() == 1);
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false, "", "Unavailable"];
}
}
</script>
<script type="text/javascript">
$(function () {
$("#datepicker").datepicker({
beforeShowDay: unavailable,
minDate: 0
});
});
</script>
I'm having trouble trying to combine only showing Mondays as well as disabling specific dates on the beforeShowDay parameter of the jQuery datepicker... I want the user to only be able to select Mondays, except for 2/20/2012 and 2/27/2012 but am not sure how to implement this...
<script type="text/javascript">
var unavailableDates = ["20-02-2012", "27-12-2012"];
function unavailable(date) {
dmy = (date.getDay() == 1);
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false, "", "Unavailable"];
}
}
</script>
<script type="text/javascript">
$(function () {
$("#datepicker").datepicker({
beforeShowDay: unavailable,
minDate: 0
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将传入的日期与另一个日期对象进行比较。相反,您将其与字符串数组中的项目进行比较。
我将使用
valueOf
或getTime
,它们返回自 UTC 1 月 1 日以来的毫秒数进行比较:示例: http://jsfiddle.net/aThZG/
You need to compare the passed in date with another date object. Instead, you're comparing it with items in an array of strings.
I would use
valueOf
orgetTime
, which return the number of milliseconds since 01 January UTC to make the comparison:Example: http://jsfiddle.net/aThZG/