여기 두 날짜를 fromDate
하고 toDate
난 있는지 확인하려면, fromDate
< toDate
날이 작은하지만에만 확인됩니다. 예를 들어, 당신은 넣어 경우 fromDate: 01/01/2016
와 toDate: 15/01/2016
잘 작동하지만 넣어 경우 fromDate: 01/01/2016
와 toDate: 15/10/2016
는 어떤 오류가 발생하지 않습니다.
다음은 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>
날짜 개체를 가져온 다음 값을 비교해야합니다. 귀하의 경우 날짜 비교 대신 문자열 비교를 수행합니다.
이 datepicker.getDate()
메서드를 사용 하여 입력 필드에서 현재 선택한 날짜 개체를 가져올 수 있습니다 .
$(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").datepicker('getDate');
var toDate = $("#tDate").datepicker('getDate');
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 type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/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>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다