はここで私は二つの日付fromDate
とtoDate
を持っているが、私は日が小さくfromDate
< toDate
それだけかどうかをチェックするかどうかを確認します。たとえば、fromDate: 01/01/2016
とtoDate: 15/01/2016
をうまく入れても、fromDate: 01/01/2016
とtoDate: 15/10/2016
を入力してもエラーは発生しません。チェック開始日は、(任意のpluguinを使用せずに)終了日より小さい場合
ここに私のコードはjsFiddleです。
$(function() {
$(".date-picker").datepicker({
dateFormat: 'dd/mm/yy'
});
$(".date-picker").each(function() {
$(this).add($(this).next()).wrapAll('<div class="imageInputWrapper"></div>');
});
$('input:button').click(function(e) {
$("#fDate").removeClass("red");
$("#tDate").removeClass("red");
var fromDate = $("#fDate").val();
var toDate = $("#tDate").val();
if (toDate <= fromDate) { //here only checks the day not month and year
$("#fDate").addClass("red");
$("#tDate").addClass("red");
errors++;
}
if (errors) e.preventDefault();
});
});
.imageInputWrapper {
width: 172px;
border: solid 1px white;
background-color: white;
display: flex;
align-items: center;
box-shadow: 0 2px 2px 0 #C2C2C2;
}
.red {
box-shadow: 0px 0px 2px 2px red;
}
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<form>
<table>
<tr>
<td>
<input id="fDate" class="date-picker" type="text" name="fromDate" style="width: 130px; height: 41px; background-color: white; border: none; outline: none; margin-left:5px" />
<img src="http://s9.postimg.org/nl2mcq2rv/calendar.png" id="fromDateImgId">
</td>
</tr>
<tr>
<td>
<input id="tDate" class="date-picker" type="text" name="toDate" style="width: 130px; height: 41px; background-color: white; border: none; outline: none; margin-left:5px" />
<img src="http://s9.postimg.org/nl2mcq2rv/calendar.png" id="toDateImgId">
</td>
</tr>
<input type="button" value="submit">
</table>
</form>
ような何かを行うことができ、あなたがすべき期待の日付の例をDateオブジェクトをチェックアウトすることができ10月15日が1月1日以降であるため、実際に失敗する(fromDate:01/01/2016とtoDate:15/10/2016)。 –