如何根据其他日期的输入更新日期
How can I update a date based on the input from another date?
我在一个页面中有一个表单,其中有两个接受日期的输入。如何使用jQuery根据输入#1的日期自动填充输入#2?基本上,我希望输入#2是从输入#1的日期起1年。
谢谢。
试试这个:
$("#input1").datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function(dateStr) {
var d = $.datepicker.parseDate('dd/mm/yy', dateStr);
var years = 1;
d.setFullYear(d.getFullYear() + years);
$('#input2').datepicker('setDate', d);
}
});
${'#input1').change(function(){
date = new Date($('#input1').val()); // You may have to parse this, depending on the format of the input
$('#input2').val(date + (365 * 24 * 60 * 60 * 1000)); // JS Date object counts in milliseconds. You may have to format this with a few lines of code, depending on what formatting you want
});
相关文章:
- 正在更新起始日期角度日期范围选择器中的日期选择
- 在日期更改后更新Angular UI引导程序日期选择器选项
- 如何根据其他日期的输入更新日期
- 更新URL时使用Javascript函数显示日期
- 使用 JavaScript 更新日期
- 如何在页面上显示时间、日期IP和URL?更新日期:2015年2月25日
- 如何更新日期?当我运行应用程序时,它被卡住了
- jQuery日期选择器在Firefox和IE的MVC部分视图上进行ajax更新后无法工作
- AngularJS没有't在Django管理日期小部件上的jQuery事件后更新ng模型
- Bootstrap日期选择器中的更新不起作用
- CouchDB 日期格式自动更新
- Javascript 日期意外自动更新
- 如何更新 cookie 值(并且不更改到期日期)?JavaScript
- 如何在不刷新浏览器的情况下更新倒计时达到 0 时的日期
- 如何在引导日期范围选取器日期更改时更新绑定
- jQuery + Boostrap DatePicker:如何让两个日期选择器输入相互更新
- 以编程方式更新 Webshim 日期在 IE 8 中不起作用
- 如何将日期更新为UTC-8的当前日期
- 使用修改日期更新文本区域
- jQuery .val不根据输入日期更新DOM