jQuery datepicker-来自另一个datepicker的defaultDate(动态) [英] jQuery datepicker - defaultDate (dynamically) from another datepicker

查看:162
本文介绍了jQuery datepicker-来自另一个datepicker的defaultDate(动态)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻我有两个日期选择器,一个是开始日期,另一个是结束日期.

I have two datepickers at the moment, one for a start date, and another for an end date.

当您选择第一个日期时,我希望将第二个日期选择器的默认值设置为相同的日期.如果我使用setDate可以正常工作并且将值设置得很好,但是默认值不会改变-如果在加载日期选择器时设置defaultDate,则它可以工作,但是如果我尝试在日期选择器上进行设置飞不行.

When you select the first date, I'd like the default value of the second datepicker to be set to the same date. If I use the setDate it works and sets the value just fine, but the default value won't change - if I set the defaultDate when the datepicker is loaded, it works, but if I try to set it on the fly it doesn't.

这是我的代码:

if($('#startDate').val().length == 10 && $("#endDate").val().length != 10) {
    $("#endDate").datepicker("defaultDate", $("#startDate").datepicker("getDate"));
}

(编辑)为澄清起见,我不想设置日期-用户需要这样做,但我希望datepicker可以直接移到与开始日期相同的日期,以免他们不得不拖曳无数页面.

(edit) for clarification, I don't want to set the date - the user needs to do that, but I'd like the datepicker to go straight to the same date as the start date, to save them having to trawl through numerous pages.

以下是(固定)工作代码: http://jsfiddle.net/c8H5y/

Here's the (kinda) working code: http://jsfiddle.net/c8H5y/

任何建议都将受到欢迎,谢谢!

Any suggestions would be very welcome, thank you!

推荐答案

这应该做到:

$("#dep_date").datepicker({
    dateFormat: 'dd/mm/yy',
    onSelect: function(dateText, inst) {
        var date = $.datepicker.parseDate('dd/mm/yy', dateText);
        var $ret_date = $("#ret_date");
        $ret_date.datepicker("option", "defaultDate", date);
    }
});

$("#ret_date").datepicker({
    dateFormat: 'dd/mm/yy',
});

jsFiddle

这篇关于jQuery datepicker-来自另一个datepicker的defaultDate(动态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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