当用户选择第一个使用Datepicker插件时,如何填充第二个日期字段? [英] how to populate second date field when user select the first one with Datepicker plugin?
本文介绍了当用户选择第一个使用Datepicker插件时,如何填充第二个日期字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想自动填写第二个日期字段,其中添加了用户从jquery提供的datefield的datpicker选择的第一个日期添加了7天。我尝试了这段代码,但是即使我想要添加一个月,也添加了一个月。
I want to auto fill the second date field with 7 days added to the first date that user selects from the datpicker for the datefield provided with jquery. I tried this code but it is adding a month even though I want it to add 7 days.
$("#to").datepicker();
$("#from").datepicker({
onSelect:function(){
var date=$(this).datepicker('getDate');
$("#to").datepicker("setDate",new Date(date.getTime()));
$("#to").datepicker("setDate", "+7d");
}
});
推荐答案
$("#to").datepicker();
$("#from").datepicker({
onSelect:function(){
var date=$(this).datepicker('getDate');
date.setDate(date.getDate()+7); // Add 7 days to the selected day
$("#to").datepicker("setDate", date);
}
});
这篇关于当用户选择第一个使用Datepicker插件时,如何填充第二个日期字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文