0
我想根据用户输入“天”字段的天数自动填充“end_date”字段。例如,用户在天数字段中输入2。然后用户选择开始日期04/27/2016。结束日期应填写2016年4月29日。我对JavaScript并不是很熟悉,我花了几个小时搜索,但目前为止还没有答案。任何帮助,将不胜感激。自动填充第二个日期字段工作不正常 - jQuery datepicker
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
</html>
<input id='days' class='days' type='text'/>
<input id='start_date' class='start_date' type='text'/>
<input id='end_date' class='end_date' type='text'/>
<script>
$(function() {
$(".days").val();
$(".end_date").datepicker();
$(".start_date").datepicker({
onSelect:function(){
var x = $(".days").val();
var toDate = $(this).datepicker('getDate');
toDate.setDate(toDate.getDate() + x)
$(".end_date").datepicker("setDate", toDate);
}
});
});
</script>
使用此代码,而不是你的代码: 变种X = $( “#天”)VAL(); – Dilip
检查它,并让我知道 – Dilip
@Dilip我只是试过了,仍然没有运气。它显示错误的日期。如果我输入1天和4/01/2016开始,结束日期显示4/11/2016。也许某种格式问题? –