我无法正确显示我的日期。我在选择日期选择星期五。示例:如果我选择星期一 26.8 日期选择器返回(onselect)星期五 30.8。日期格式必须为 dd.mm.yy。
这是代码:http: //jsfiddle.net/JBrvn/8/
$(function () {
$('#to').attr('disabled', true);
$("#from").datepicker({
dateFormat: 'dd.mm.yy',
onSelect: function (selectedDate) {
var x = selectedDate.split('.');
var d = new Date(x[1] + ',' + x[0] + ',' + x[2]);
var res = d.setDate(d.getDate() + 7);
var dateMsg = d.getDate() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear();
$("#to").removeAttr('disabled').removeClass('hasDatepicker').datepicker({
minDate: dateMsg,
dateFormat: 'dd.mm.yy',
onSelect: function (date) {
var d = new Date(date);
var index = d.getDay();
if (index == 0) {
d.setDate(d.getDate() + 5);
}
else if (index == 1) {
d.setDate(d.getDate() + 4);
}
else if (index == 2) {
d.setDate(d.getDate() + 3);
}
else if (index == 3) {
d.setDate(d.getDate() + 2);
}
else if (index == 4) {
d.setDate(d.getDate() + 1);
}
else if (index == 5) {
d.setDate(d.getDate() + 0);
}
else if (index == 6) {
d.setDate(d.getDate() + 6);
}
var curr_day = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
$(this).val((curr_day<10? "0":"")+curr_day + "." +(curr_month<10? "0":"")+curr_month + "." + curr_year);
}
});
}
});
});