首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自动填写第二个日期字段不能正常工作- jQuery数据报警器

自动填写第二个日期字段不能正常工作- jQuery数据报警器
EN

Stack Overflow用户
提问于 2016-04-27 14:39:23
回答 1查看 589关注 0票数 0

我试图根据用户在“天”字段中输入的天数自动填充"end_date“字段。例如,用户输入2 in days字段。然后,用户开始选择2016年4月27日开始的日期。结束日期应为2016年9月4日。我对javascript不是很熟悉,我花了几个小时搜索,但到目前为止还没有答案。任何帮助都将不胜感激。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-27 15:54:50

我不断尝试一些事情,并能够找到一种方法,使这段代码工作。这可能不是最好的方法,但它对我想要做的事情有效。我将这一行代码从toDate.setDate(toDate.getDate() + x)改为toDate.setDate(toDate.getDate() + (x / 1))。

代码语言:javascript
复制
<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() {
$(".on_site_days").val();
$(".audit_end_date").datepicker();
$(".audit_start_date").datepicker({
onSelect:function(){

dateFormat : 'dd-mm-yy'

var x = $(".on_site_days").val();
var toDate = $(this).datepicker('getDate');
toDate.setDate(toDate.getDate() + (x / 1))
$(".audit_end_date").datepicker("setDate", toDate);
}
});
});
</script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36893092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档