【发布时间】:2010-11-21 17:58:45
【问题描述】:
我正在查看 jQuery UI Datepicker (http://jqueryui.com/demos/datepicker/) 的文档,但我找不到如何将一周的第一天设置为星期一。
应用区域设置会将星期一设置为一周的第一天,但这也会更改语言。
【问题讨论】:
我正在查看 jQuery UI Datepicker (http://jqueryui.com/demos/datepicker/) 的文档,但我找不到如何将一周的第一天设置为星期一。
应用区域设置会将星期一设置为一周的第一天,但这也会更改语言。
【问题讨论】:
这是我使用的示例配置。用“firstDay: 1”查看最后一行。 我认为使用这样的语法来指定日期选择器选项看起来更好;)
$('#datepickerfield').datepicker({
constrainInput: true, // prevent letters in the input field
minDate: new Date(), // prevent selection of date older than today
showOn: 'button', // Show a button next to the text-field
autoSize: true, // automatically resize the input field
altFormat: 'yy-mm-dd', // Date Format used
beforeShowDay: $.datepicker.noWeekends, // Disable selection of weekends
firstDay: 1 // Start with Monday
})
【讨论】:
尝试 firstDay 选项(在选项选项卡中):
//getter
var firstDay = $('.selector').datepicker('option', 'firstDay');
//setter
$('.selector').datepicker('option', 'firstDay', 1);
【讨论】:
将第一天用作星期一:
$(function() {
$( "#date_id" ).datepicker({ firstDay: 1 });
});
【讨论】:
您还可以通过为您的语言创建自己的本地化文件以及您自己的设置来实现这一点。详情见本页:http://docs.jquery.com/UI/Datepicker/Localization
【讨论】:
function getFirstDateOfThisWeek(d)
{
var TempDate = new Date(d || new Date());
TempDate.setDate(TempDate.getDate() + (@Config.WeekStartOn - 1 - TempDate.getDay() - 7) % 7);
return TempDate;
}
var StartDate = getFirstDateOfThisWeek(new Date()); //1st date of this week
【讨论】: