仅当此日期在“开始日期 + 5 天”和“结束日期 - 14 天”中时,如何在 datepicker jQuery UI 中显示日期(在 #id_erinnerung_am 字段中)。只有这些日期,其他禁用。
$(function() {
$( ".vDateField" ).datepicker({ dateFormat: 'dd.mm.yy' });
});
我的脚本 Js:
TIME_UNITS = {
'1': 'days',
'2': 'months',
'3': 'years'
}
function get_date_from_string(strDate) {
var dateParts = strDate.split('.');
var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
return date;
}
function recalculate_deadline() {
var = startdate = $('#id_laufzeit_von').val(); #START DATE
var enddate = $('#id_laufzeit_bis').val(); #ENDDATE
if (!enddate) {
return;
}
enddate = moment(new get_date_from_string(enddate));
// get cancelling period and unit
var timeunit_cancelling = TIME_UNITS[$('#id_kuendigungsfrist_type').val()];
var cancelling_deadline = $('#id_kuendigungsfrist').val();
if (!cancelling_deadline) {
return;
}
cancelling_deadline = parseInt(cancelling_deadline, 10);
enddate.subtract(timeunit_cancelling, cancelling_deadline);
// show date in input field
var $cancel_until = $('#id_kuendigung_moeglichbis');
$cancel_until.val(enddate.format('DD.MM.YYYY'));
$cancel_until.change();
}
function check_reminder_date() {
var $reminder_date = $('#id_erinnerung_am');
var $cancel_until = $('#id_kuendigung_moeglichbis');
reminder_date = $reminder_date.val();
cancel_until = $cancel_until.val();
if (!cancel_until) {
return;
}
cancel_until = get_date_from_string(cancel_until);
// If reminder_date is set, check that it is earlier than cancelling date
if (reminder_date) {
reminder_date = get_date_from_string(reminder_date);
if (reminder_date <= cancel_until) {
// everything is fine, just return
return;
}
}
// correct or set date for reminder
reminder_date = moment(cancel_until);
reminder_date.subtract('months', 1);
$reminder_date.val(reminder_date.format('DD.MM.YYYY'));
$reminder_date;
//alert(reminder_date); //Fri Mar 15 2013 00:00:00 GMT+0100 (CET)
$reminder_date.datepicker(setValue(reminder_date));
}
$(document).ready(function(){
$('#id_laufzeit_bis').datepicker().on('changeDate', recalculate_deadline);
$('#id_kuendigungsfrist').change(recalculate_deadline);
$('#id_kuendigungsfrist_type').change(recalculate_deadline);
$('#id_kuendigung_moeglichbis').change(check_reminder_date);
$('#id_erinnerung_am').datepicker('hide').on(check_reminder_date);
});
怎么做?我是 Java Script 的新手