使用 Jquery datepicker 添加具有选定日期的一天
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16117718/
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
Add a day with selected date using Jquery datepicker
提问by J?cob
I have been trying to add a day for another date field with date selected of current field
我一直在尝试为另一个日期字段添加一天,并选择当前字段的日期
,
onSelect: function(date) {
var date2 = $('.currDate').datepicker('getDate');
date2.setDate(date2.getDate()+1);
$('.nextDt').datepicker('setDate', date2);
}
However I am getting at date2.setDate(date2.getDate()+1);
但是我正在 date2.setDate(date2.getDate()+1);
Message: Object doesn't support this property or method
How can I solve this issue?
我该如何解决这个问题?
回答by Arun P Johny
It is because, currDate
might be empty.
这是因为,currDate
可能是空的。
If currDate
is emtpy $('.currDate').datepicker('getDate')
will return null
in which case date2.setDate(date2.getDate()+1);
could throw the error
如果currDate
是 emtpy$('.currDate').datepicker('getDate')
将返回,null
在这种情况下 date2.setDate(date2.getDate()+1);
可能会抛出错误
Update:
更新:
$(function() {
$('#nxtDate').datepicker({
dateFormat: "dd-M-yy",
});
$("#currDate").datepicker({
dateFormat: "dd-M-yy",
minDate: 0,
onSelect: function(date){
var date2 = $('#currDate').datepicker('getDate');
date2.setDate(date2.getDate()+1);
$('#nxtDate').datepicker('setDate', date2);
}
});
})
回答by Zaheer Ahmed
setDate
and getDate
are the functions supported by Date()
of js while you getDate from datepicker it returns as string so you need to convert it or try this code:
setDate
并且getDate
是Date()
js支持的函数,当您从 datepicker 获取日期时,它以字符串形式返回,因此您需要对其进行转换或尝试以下代码:
onSelect: function(date) {
if(date!=undefined){
var dateObject=new Date(date);
dateObject.setDate(dateObject.getDate()+1);
$('.nextDt').datepicker('setDate', dateObject);
}
}
回答by Uttam Swamy
echo date('d-m-Y', strtotime("+".$nod." days"));
nod= Number of days
点头=天数