使用 Jquery datepicker 添加具有选定日期的一天 [英] Add a day with selected date using Jquery datepicker

查看:30
本文介绍了使用 Jquery datepicker 添加具有选定日期的一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试为另一个日期字段添加一天,并选择当前字段的日期

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);
    }

但是我得到了 date2.setDate(date2.getDate()+1);

Message: Object doesn't support this property or method

我该如何解决这个问题?

How can I solve this issue?

推荐答案

这是因为,currDate 可能为空.

It is because, currDate might be empty.

如果 currDate 是 emtpy $('.currDate').datepicker('getDate') 将返回 null 在这种情况下 date2.setDate(date2.getDate()+1); 可能会抛出错误

If currDate is emtpy $('.currDate').datepicker('getDate') will return null in which case date2.setDate(date2.getDate()+1); could throw the error

更新:

$(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);
        }
    });
})

这篇关于使用 Jquery datepicker 添加具有选定日期的一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆