我有一个表格,询问开始日期和结束日期。这是我的代码:
$('input[name="start"]').on('change', function(){
var max_months = 3;
var start = new Date($(this).val());
var end = new Date(start.setMonth(start.getMonth() + max_months));
$('input[name="end"]').val(end);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="date" name="start">
<input type="date" name ="end">
</form>
&#13;
所以,如果我要选择一个日期&#34; 02/02/208&#34;。结束日期将转为&#34; 005/202/2018&#34;
答案 0 :(得分:3)
您可以执行以下操作:
$('input[name="start"]').on('change', function(){
var max_months = 3;
var start = new Date($(this).val());
start.setMonth(start.getMonth() + max_months); /* Add 3 months */
var day = ("0" + start.getDate()).slice(-2);
var month = ("0" + (start.getMonth() + 1 )).slice(-2);
var end = start.getFullYear()+"-"+(month)+"-"+(day) ;
$('input[name="end"]').val(end);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="date" name="start">
<input type="date" name ="end">
</form>