jQuery UI Datepicker 仅启用数组中的特定日期 [英] jQuery UI Datepicker enable only specific days in array

查看:22
本文介绍了jQuery UI Datepicker 仅启用数组中的特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图禁用日期选择器中的所有日期,只启用数组中的日期.这是我到目前为止的代码 http://jsfiddle.net/peter/yXMKC/ 问题仅 5 月 14 日显示为已启用.其他的都是残疾人.有任何想法吗?

I am trying to disable all dates in a datepicker and only enable dates which are in an array. This is the code I have so far http://jsfiddle.net/peter/yXMKC/ the problem is only May 14th shows up as enabled. The others are all disabled. Any ideas?

var availableDates = ["9-5-2011","14-5-2011","15-5-2011"];

function available(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
  if ($.inArray(dmy, availableDates) == 1) {
    return [true, "","Available"];
  } else {
    return [false,"","unAvailable"];
  }
}

$('#date').datepicker({ beforeShowDay: available });

推荐答案

$.inArray(dmy, availableDates) 返回元素的索引,所以当你与 1 比较时,只有 14-5-2011 会匹配.检查不等于-1.应该可以.

$.inArray(dmy, availableDates) returns the index of the element, so when you compare with 1 only 14-5-2011 will match. Check for not equal to -1. Should work.

小提琴 - http://jsfiddle.net/yXMKC/4/

var availableDates = ["9-5-2011","14-5-2011","15-5-2011"];

function available(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
  console.log(dmy+' : '+($.inArray(dmy, availableDates)));
  if ($.inArray(dmy, availableDates) != -1) {
    return [true, "","Available"];
  } else {
    return [false,"","unAvailable"];
  }
}

这篇关于jQuery UI Datepicker 仅启用数组中的特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆