在这段代码中,我向您展示了如何做到这一点的基础知识,它可以进行优化,您可能可以在服务器端生成 days var,但想向您展示全貌
$("#datepicker").datepicker();
var today = new Date();
var add30Days = new Date();
var add60Days = new Date();
var add90Days = new Date();
add30Days.setDate(today.getDate() + 30);
add60Days.setDate(today.getDate() + 60);
add90Days.setDate(today.getDate() + 90);
var formated30date = (add30Days.getMonth() + 1) + '/' + add30Days.getDate() + '/' + add30Days.getFullYear();
$("#datepicker").val(formated30date);
编辑:我看到您仍在询问此问题,因此我更新了代码以使其功能齐全:
$("#datepicker").datepicker();
$('button').on('click', function() {
var today = new Date();
var addDays = new Date();
var days = parseInt($(this).attr("id").split("_")[1],10);
addDays.setDate(today.getDate() + days);
var newDate = (addDays.getMonth() + 1) + '/' + addDays.getDate() + '/' + addDays.getFullYear();
$("#datepicker").val(newDate);
});
查看新演示