我们使用此插件实现了日期选择器作为预订流程的一部分 -
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) 不是函数”
有人可以提供任何指导吗?
最佳答案
正如我所见,您正在使用 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
变量不是字符串,而是 Date 对象数组。
关于javascript - Jquery Date - 确定星期日?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30942538/