Javascript 将 setDate 与 jQueryUi 日期选择器一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4692048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using setDate with jQueryUi datepicker
提问by Richard L
I'm trying to set the date of another datepicker exactly 1 year on from the original datepicker on close.
我试图在关闭时将另一个日期选择器的日期设置为与原始日期选择器相差 1 年。
I have the following code:
我有以下代码:
$("#myDatepicker1").datepicker({
onClose: function(dateText, inst) {
$("#myDatepicker2").datepicker("setDate", dateText +1y);
}
});
As you can guess this isn't working.
你可以猜到这是行不通的。
Any help would be great.
任何帮助都会很棒。
Thanks in advance!
提前致谢!
Richard
理查德
回答by Arthur Neves
You can try something like that:
你可以尝试这样的事情:
d = $("#myDatepicker1").datepicker("getDate");
$("#myDatepicker2").datepicker("setDate", new Date(d.getFullYear()+1,d.getMonth(),d.getDate()));
EDIT:
编辑:
This is the solution to add one year, just to make sure that this is the piece which was missing right?! the on close it`s working fine right?!
这是增加一年的解决方案,只是为了确保这是丢失的部分,对吗?!在关闭它工作正常吗?!