我无法更正显示我的约会。我在选择日期选择星期五。例如:如果我选择星期一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);
}
});
}
});
});
答案 0 :(得分:1)
Date对象是javascript,而不是jQuery,因此它不遵守jQuery datepicker的日期格式。为了使用第一个datepicker的结果创建一个日期对象来提供第二个,你需要将它转换为Date
理解的格式,可能:
onSelect: function (dateString) {
var date = dateString.split("."); //split the string into an array
var d = new Date(date[2],date[1],date[0]); //feed the year, month, and date in the order Date expects