我想将datedicker的日期范围'fromdate'设置为'afterdate'至少1年。我使用bootstrap作为datepicker并已经设置输入类型id'fromdate'和'afterdate'在javascript函数中调用。
这是我设法做到的:
<div class="input-append success date">
<input type="text" class="form-control" value="<?= $_POST['fromdate'] ?>" name="fromdate" id="fromdate" style="width:185px;">
<span class="add-on"><span class="arrow"></span><i class="fa fa-th"></i></span>
</div>
<div class="input-append success date">
<input type="text" class="form-control" value="<?= $_POST['nextdate'] ?>" name="nextdate" id="nextdate" style="width:185px;">
<span class="add-on"><span class="arrow"></span><i class="fa fa-th"></i></span>
</div>
<script>
function validateReportRangeForm(){
var x = document.forms["daterange"]["fromdate"].value.trim();
var y = document.forms["daterange"]["nextdate"].value.trim();
var x = x.split("-").reverse().join("/");
var y = y.split("-").reverse().join("/");
if ((Date.parse(x) > Date.parse(y))) {
alert("'From Date' should be greater than 'To Next Days'");
document.forms["daterange"]["nextdate"].focus();
return false;
}
}
</script>
输出: