我正在使用两个jQuery日期选择器来选择日期范围。有没有办法选择整周?这意味着在打开开始日期选择器时,将有两种选择方法:
在asp日历中,可以通过将SelectionMode属性设置为“DayWeek”来完成类似的操作,但我无法在jQuery datepicker中实现这一点。可以吗?
答案 0 :(得分:3)
以下是我最终如何实现这一点:
// A click on a week number cell in the weeks column of the start datepicker
$("td.ui-datepicker-week-col").live("click", function()
{
// Simulate a click on the first day of the week
$(this).next().click();
// Grab the date, and set the end of the week in the end datepicker
var fromDate = $("#inputStartDate").datepicker("getDate");
var toDate = fromDate;
toDate.setDate(fromDate.getDate() + 6);
$("#inputEndDate").datepicker("setDate", toDate);
});
答案 1 :(得分:1)
以下是可以单击两个输入字段的示例:
$(document).ready(function(){
// date picker for Export part
$(".datePicker").datepicker(
{
dateFormat: 'yymmdd',
showWeek: true,
firstDay: 1,
weekHeader: "",
showOtherMonths: true,
selectOtherMonths: true
}
).focus(function(){
// prevent focus event firing twice
var $this = $(this);
var now = +new Date();
var lastClicked = $this.data("lastClicked");
if (lastClicked && (now - lastClicked) < 100) {
// Don't do anything
return;
}
$this.data("lastClicked", now);
var el = this;
// A click on a week number cell in the weeks column of the start datepicker
$("td.ui-datepicker-week-col").click(function(){
// Simulate a click on the first day of the week
$(this).next().click();
var selectedDate = $(el).datepicker("getDate");
$("#inputStartDate").datepicker("setDate", selectedDate);
var toDate = selectedDate;
toDate.setDate(toDate.getDate() + 6);
$("#inputEndDate").datepicker("setDate", toDate);
});
});
});