La mia domanda è. Perché questo errore si verifica solo quando scelgo CheckIn_Date in agosto e settembre?jQuery. ASP.NET MVC 3. Bug di Datepicker?
Ho un progetto che utilizza ASP.NET MVC 3 e utilizza jQuery per il selettore di date. Diciamo che ho 3 caselle di testo denominate CheckIn_Date
, CheckOut_Date
(queste due che usano datepicker) e Days
a mio avviso.
Quando imposto Giorni = 3, quindi scelgo CheckIn_Date = 2012-01-01, il mio CheckOut_Date conterà automaticamente i giorni e imposterà il valore a 2012-01-03.
Tutto va come mi aspetto, fino a quando non scelgo 2012-08-01 nel mio CheckIn_Date e imposto i giorni = 3. Il mio valore CheckOut_Date non è 2012-08-04 ma 2012-12-04. Questo accade solo quando scelgo il mio CheckIn_Date in agosto e settembre. Scegliendo un altro mese dammi quello che mi aspetto per il mio CheckOut_Date.
Ecco il mio codice:
$("input[data-datepicker='true']").change(function() {
var id = $(this).attr("name");
var days = parseInt($("#maxProgramDays").val());
//var o = new Date();
var val = $(this).val();
var s = val.split("-");
var x = [];
var thisDate = new Date();
thisDate.setFullYear(parseInt(s[0]), parseInt(s[1]) - 1, parseInt(s[2]));
//alert(thisDate.toDateString())
if (id == "Reservation[0].CheckIn_Date") {
thisDate.setDate(thisDate.getDate() + days);
x['year'] = thisDate.getFullYear();
x['month'] = m2d(thisDate.getMonth() + 1);
x['day'] = m2d(thisDate.getDate());
$("input[name='Reservation[0].CheckOut_Date']").val(x['year'] + '-' + x['month'] + '-' + x['day']);
//alert(thisDate.toDateString())
}
if (id == "Reservation[0].CheckOut_Date") {
thisDate.setDate(thisDate.getDate() - days);
x['year'] = thisDate.getFullYear();
x['month'] = m2d(thisDate.getMonth() + 1);
x['day'] = m2d(thisDate.getDate());
$("input[name='Reservation[0].CheckIn_Date']").val(x['year'] + '-' + x['month'] + '-' + x['day']);
//alert(thisDate.toDateString())
}
Ecco il mio Vista:
<div class="display-label">Program Days</div>
<div class="display-field"><span id="pDays"></span></div>
<div class="editor-label">@Html.LabelFor(model => model.Reservation[0].CheckIn_Date)</div>
<div class="editor-field reserveDate">
@Html.Datepicker("Reservation[0].CheckIn_Date", "")
@Html.ValidationMessageFor(model => model.Reservation[0].CheckIn_Date)
</div>
<div class="editor-label">@Html.LabelFor(model => model.Reservation[0].CheckOut_Date)</div>
<div class="editor-field reserveDate">
@Html.Datepicker("Reservation[0].CheckOut_Date", "")
@Html.ValidationMessageFor(model => model.Reservation[0].CheckOut_Date)
</div>
Che cos'è 'm2d'? È una funzione javascript personalizzata? Inserisci il codice per questo. –
scusa per risposta tardiva, sì m2d è funzione come questa funzione m2d (m) { var x; if (parseInt (m) <10) { x = '0' + m; } else { x = m; } ritorno x; } –
+1 alla domanda, trovata una soluzione interessante. –