gpt4 book ai didi

javascript - 输入起始日期后更改截止日期

转载 作者:行者123 更新时间:2023-12-03 00:57:33 25 4
gpt4 key购买 nike

我有一个字段。一个是 ValidFrom 日期,另一个是 ValidTo 日期。

我的问题是,如果使用DateTimePicker输入ValidFrom日期,我应该如何将ValidTo更改为3 0 auto 天数?

以下是我的DateTimePicker代码:

<script src="~/Scripts/jquery.datetimepicker.js"></script>
<script>
$(document).ready(function () {
$('#ValidFrom').datetimepicker({
datepicker: true,
timepicker: false,
format: 'm/d/Y',
step: 30,
minDate: new Date(),
onChangeDateTime: function (dp, $input) {
var date = new Date($input.val());
date.setMonth(date.getMonth() + 1);
$('#ValidTo').datetimepicker({
datepicker: true,
timepicker: false,
format: 'm/d/Y',
step: 30,
minDate: date,
});
},

});

});
</script>

I have to change the ValidTo date by 30 days as and when ValidFrom date is entered.

最佳答案

代码应该是这样的:经过多次尝试才完成

<script>
$(document).ready(function () {
$('#ValidFrom').datetimepicker({
datepicker: true,
timepicker: false,
format: 'm/d/Y',
step: 30,
minDate: new Date(),
onChangeDateTime: function (dp, $input) {
var date = new Date($input.val());
date.setMonth(date.getMonth() + 1);
date = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
$('#ValidTo').val(date);
},

});
$('#ValidTo').datetimepicker({
datepicker: true,
timepicker: false,
format: 'm/d/Y',
step: 30,
minDate: new Date()
});
});

</script>

关于javascript - 输入起始日期后更改截止日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52759303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com