Jquery 日期 - 确定星期日?
Jquery Date - determine a sunday?
我们已经使用此插件将日期选择器作为预订流程的一部分 -
http://keith-wood.name/datepick.html
它基本上是在与日期列相对应的列中填充一系列带有月份日期的 div - 我们遇到的问题是禁用星期日..
所以 - 我们正在尝试使用以下代码从日期字符串中检测短语 sun -
$('#calendar').datepick({
pickerClass: 'noPrevNext',
dateFormat: 'yyyy/mm/dd',
altField: '[name="delivery-date"]',
defaultDate: +7,
minDate: +1,
maxDate: +45,
changeMonth: false,
showTrigger: null,
onSelect: function(dates)
{
var jim = dates.indexOf("Sun");
if (jim >= 0)
{
alert('Sundays are not selectable');
}
}
});
但我们收到一条错误消息 'indexof(sun) is not a function'
谁能给点指导啊!?
如我所见,您使用的 Keith Wood Datepicker 插件与 jquery UI 插件非常相似。在这种情况下,您的 onSelect
函数接收日期对象,如以下所述:
The function is called when each date is selected and receives the currently selected dates (Date[]) as the parameter.
因此您可以直接从 dates
数组调用 getDay()
方法:
onSelect: function(dates)
{
var jim = dates[0].getDay();
if (jim == 0)
{
alert('Sundays are not selectable');
$('#calendar').val("");
}
}
您的问题:dates
变量不是字符串,而是日期对象数组。
我们已经使用此插件将日期选择器作为预订流程的一部分 -
http://keith-wood.name/datepick.html
它基本上是在与日期列相对应的列中填充一系列带有月份日期的 div - 我们遇到的问题是禁用星期日..
所以 - 我们正在尝试使用以下代码从日期字符串中检测短语 sun -
$('#calendar').datepick({
pickerClass: 'noPrevNext',
dateFormat: 'yyyy/mm/dd',
altField: '[name="delivery-date"]',
defaultDate: +7,
minDate: +1,
maxDate: +45,
changeMonth: false,
showTrigger: null,
onSelect: function(dates)
{
var jim = dates.indexOf("Sun");
if (jim >= 0)
{
alert('Sundays are not selectable');
}
}
});
但我们收到一条错误消息 'indexof(sun) is not a function'
谁能给点指导啊!?
如我所见,您使用的 Keith Wood Datepicker 插件与 jquery UI 插件非常相似。在这种情况下,您的 onSelect
函数接收日期对象,如以下所述:
The function is called when each date is selected and receives the currently selected dates (Date[]) as the parameter.
因此您可以直接从 dates
数组调用 getDay()
方法:
onSelect: function(dates)
{
var jim = dates[0].getDay();
if (jim == 0)
{
alert('Sundays are not selectable');
$('#calendar').val("");
}
}
您的问题:dates
变量不是字符串,而是日期对象数组。