Ich habe folgenden Code:Wie Tage zu deaktivieren, basierend auf Benutzer wählen Jquery Datepicker
html
<p>from</p>
<input type="text" class="spromotion-input-inbody spromotion-input-datepick" id="sproid-bookingcondition-datefrom">
<p>to</p>
<input type="text" class="spromotion-input-inbody spromotion-input-datepick" id="sproid-bookingcondition-dateto">
<p>
select days of the week
</p>
<div>
<div class="spromotion-condition-datepickerbox" id="sproid-bookingcond-aplicabledays">
<label name="promo-type" class="radio-inline spromotion-aplicabledays-checkbx">
<input type="checkbox" value="sunday" name="condition-aplicable-day" checked>S
</label>
<label name="promo-type" class="radio-inline spromotion-aplicabledays-checkbx">
<input type="checkbox" value="monday" name="condition-aplicable-day" checked>M
</label>
<label name="promo-type" class="radio-inline spromotion-aplicabledays-checkbx">
<input type="checkbox" value="tuesday" name="condition-aplicable-day" checked>T
</label>
<label name="promo-type" class="radio-inline spromotion-aplicabledays-checkbx">
<input type="checkbox" value="wednesday" name="condition-aplicable-day" checked>W
</label>
<label name="promo-type" class="radio-inline spromotion-aplicabledays-checkbx">
<input type="checkbox" value="thursday" name="condition-aplicable-day" checked>T
</label>
<label name="promo-type" class="radio-inline spromotion-aplicabledays-checkbx">
<input type="checkbox" value="friday" name="condition-aplicable-day" checked>F
</label>
<label name="promo-type" class="radio-inline spromotion-aplicabledays-checkbx">
<input type="checkbox" value="saturday" name="condition-aplicable-day" checked>S
</label>
</div>
</div>
Skript
$(function() {
var dateFormat = "mm/dd/yy",
from = $("#sproid-bookingcondition-datefrom")
.datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on("change", function() {
to.datepicker("option", "minDate", getDate(this));
}),
to = $("#sproid-bookingcondition-dateto").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on("change", function() {
from.datepicker("option", "maxDate", getDate(this));
});
function getDate(element) {
var date;
try {
date = $.datepicker.parseDate(dateFormat, element.value);
} catch(error) {
date = null;
}
return date;
}
});
Meine Forderung ist Tage der zu ermöglichen Woche basierend auf Benutzerauswahl. Standardmäßig sind alle Wochendaten aktiviert. Wenn der Benutzer beispielsweise Montag und Dienstag auswählt, müssen die restlichen Daten im Kalender deaktiviert werden. Wie ist das möglich mit beforeShowDay
oder einem anderen Ansatz, um dies zu beheben.
Siehe Link für Geige: fiddle