この日付が「開始日+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スクリプトの初心者です